Ver código fonte

添加重定向

dcsunny 4 anos atrás
pai
commit
d2846b62cb
3 arquivos alterados com 17 adições e 12 exclusões
  1. 4 0
      http/handle.go
  2. 12 11
      http/reply/reply.pb.go
  3. 1 1
      http/reply/reply.proto

+ 4 - 0
http/handle.go

@@ -51,6 +51,10 @@ func ErrHandle(w http.ResponseWriter, r *http.Request, err error) {
 	w.Header().Set(ContentTypeHeader, contentType(codec.Name()))
 	if se.Code == 0 {
 		w.WriteHeader(200)
+	} else if se.Code >= 302 && se.Code <= 303 {
+		w.WriteHeader(int(se.Code))
+		http.Redirect(w, r, se.Message, int(se.Code))
+		return
 	} else {
 		if se.Code < 10000 {
 			se.Code = 10000 + se.Code

+ 12 - 11
http/reply/reply.pb.go

@@ -7,12 +7,11 @@
 package reply
 
 import (
-	reflect "reflect"
-	sync "sync"
-
 	protoreflect "google.golang.org/protobuf/reflect/protoreflect"
 	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
 	structpb "google.golang.org/protobuf/types/known/structpb"
+	reflect "reflect"
+	sync "sync"
 )
 
 const (
@@ -27,9 +26,9 @@ type SuccessReply struct {
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 
-	Code    int64           `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
-	Message string          `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
-	Data    *structpb.Value `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
+	Code    int32           `protobuf:"varint,1,opt,name=code,proto3" json:"code"`
+	Message string          `protobuf:"bytes,2,opt,name=message,proto3" json:"message"`
+	Data    *structpb.Value `protobuf:"bytes,3,opt,name=data,proto3" json:"data"`
 }
 
 func (x *SuccessReply) Reset() {
@@ -64,7 +63,7 @@ func (*SuccessReply) Descriptor() ([]byte, []int) {
 	return file_reply_proto_rawDescGZIP(), []int{0}
 }
 
-func (x *SuccessReply) GetCode() int64 {
+func (x *SuccessReply) GetCode() int32 {
 	if x != nil {
 		return x.Code
 	}
@@ -92,14 +91,16 @@ var file_reply_proto_rawDesc = []byte{
 	0x70, 0x69, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
 	0x62, 0x75, 0x66, 0x2f, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
 	0x22, 0x68, 0x0a, 0x0c, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79,
-	0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04,
+	0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04,
 	0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18,
 	0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x2a,
 	0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x67,
 	0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x56,
-	0x61, 0x6c, 0x75, 0x65, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x42, 0x1c, 0x0a, 0x03, 0x61, 0x70,
-	0x69, 0x50, 0x01, 0x5a, 0x13, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x32, 0x36,
-	0x2f, 0x61, 0x70, 0x69, 0x3b, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x61, 0x6c, 0x75, 0x65, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x42, 0x3c, 0x0a, 0x03, 0x61, 0x70,
+	0x69, 0x50, 0x01, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x2e, 0x69, 0x6b, 0x75, 0x62, 0x61, 0x6e, 0x2e,
+	0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x6b, 0x72, 0x61, 0x74, 0x6f,
+	0x73, 0x2d, 0x75, 0x74, 0x69, 0x6c, 0x73, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x72, 0x65, 0x70,
+	0x6c, 0x79, 0x3b, 0x72, 0x65, 0x70, 0x6c, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (

+ 1 - 1
http/reply/reply.proto

@@ -9,7 +9,7 @@ option java_multiple_files = true;
 option java_package = "api";
 
 message SuccessReply {
-  int64 code = 1;
+  int32 code = 1;
   string message = 2;
   google.protobuf.Value data = 3;
 }