diff --git a/go.mod b/go.mod index fc336ff..3b8e7ed 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/unistack-org/micro-api-router-static/v3 v3.2.1 github.com/unistack-org/micro-broker-http/v3 v3.3.0 github.com/unistack-org/micro-client-grpc/v3 v3.3.1 - github.com/unistack-org/micro-client-http/v3 v3.3.7 + github.com/unistack-org/micro-client-http/v3 v3.3.8 github.com/unistack-org/micro-codec-grpc/v3 v3.2.1 github.com/unistack-org/micro-codec-json/v3 v3.2.1 github.com/unistack-org/micro-codec-jsonpb/v3 v3.2.2 @@ -27,10 +27,10 @@ require ( github.com/unistack-org/micro-proto v0.0.2-0.20210227213711-77c7563bd01e github.com/unistack-org/micro-router-register/v3 v3.2.2 github.com/unistack-org/micro-server-grpc/v3 v3.3.2 - github.com/unistack-org/micro-server-http/v3 v3.3.10 + github.com/unistack-org/micro-server-http/v3 v3.3.11 github.com/unistack-org/micro-server-tcp/v3 v3.3.0 github.com/unistack-org/micro-wrapper-trace-opentracing/v3 v3.2.0 - github.com/unistack-org/micro/v3 v3.3.13 + github.com/unistack-org/micro/v3 v3.3.14 google.golang.org/genproto v0.0.0-20210416161957-9910b6c460de google.golang.org/grpc v1.37.0 google.golang.org/protobuf v1.26.0 diff --git a/go.sum b/go.sum index 64fca2c..cc4f588 100644 --- a/go.sum +++ b/go.sum @@ -457,8 +457,8 @@ github.com/unistack-org/micro-broker-http/v3 v3.3.0 h1:IjdBtcmxl4OniyHG+FAkNoZS9 github.com/unistack-org/micro-broker-http/v3 v3.3.0/go.mod h1:soBy700MUOHV5YcyIG949uxqd+FMUinQQr+Qi7ilE4A= github.com/unistack-org/micro-client-grpc/v3 v3.3.1 h1:KP3jBK+R03jffjwWbeMYkzZDIPspuyVGlVxYJxHiYeE= github.com/unistack-org/micro-client-grpc/v3 v3.3.1/go.mod h1:FG7t8s5Jb6VChxyBq75SS9v2/CA6Isikk/tOjtpa+xc= -github.com/unistack-org/micro-client-http/v3 v3.3.7 h1:zzXkHzYTBmPQA/qSycYCYMVH/0PWxIjZSgix6lkL2Ng= -github.com/unistack-org/micro-client-http/v3 v3.3.7/go.mod h1:hOoUW9Z8U3IpsvgLeDSFC51zGeLP3o/fulsfKSa0eO0= +github.com/unistack-org/micro-client-http/v3 v3.3.8 h1:DB/E2GJG7teU3Mw7q+eMqJ1SYf+Hb1wUJ91aIZIjBso= +github.com/unistack-org/micro-client-http/v3 v3.3.8/go.mod h1:hOoUW9Z8U3IpsvgLeDSFC51zGeLP3o/fulsfKSa0eO0= github.com/unistack-org/micro-codec-grpc/v3 v3.2.1 h1:C+9DHTtRSvodlVOFo0+zMhBXoIye/hMleXlRv0o1yIU= github.com/unistack-org/micro-codec-grpc/v3 v3.2.1/go.mod h1:kaEdCPyWsa4o44cD4oS0+KzJWtshlXocZgnzEY+LZHQ= github.com/unistack-org/micro-codec-json/v3 v3.2.1 h1:nMRBnEvCttwX4yPAWuRSAvzcfLazRetqO4DpqJJHjY8= @@ -485,8 +485,8 @@ github.com/unistack-org/micro-router-register/v3 v3.2.2 h1:lYCymDHkJfhZWYQ4+Sb7F github.com/unistack-org/micro-router-register/v3 v3.2.2/go.mod h1:Y9Qtlg4NHqq5rR6X6Jm+04LoSJMi7/OOCm2mRueZYTE= github.com/unistack-org/micro-server-grpc/v3 v3.3.2 h1:SeJTEmlURpry1kBGK6nXAWp02vnf2ex5CAoqqvIzulo= github.com/unistack-org/micro-server-grpc/v3 v3.3.2/go.mod h1:f8hPoI9s8fUrWU6+fLveGODU+QJ7UR4XSA3lOrTm+1Y= -github.com/unistack-org/micro-server-http/v3 v3.3.10 h1:2f5e2rcuQ7Xc2aKrw4d1F2MTWrFL89WrUsxiC9k+56s= -github.com/unistack-org/micro-server-http/v3 v3.3.10/go.mod h1:h4YLvS+WEMDAlyjq87BOL0RQzq9ZFJh49ONzPzwrvZ8= +github.com/unistack-org/micro-server-http/v3 v3.3.11 h1:j+a/idVpQvFkYUDbio2JC/JX0SLcvBNXFmalRB51fv0= +github.com/unistack-org/micro-server-http/v3 v3.3.11/go.mod h1:kAcSDkHflkXTIm/0yN3I6+u717MDgfM1knJHGH/+vM8= github.com/unistack-org/micro-server-tcp/v3 v3.3.0 h1:YIj5SvuPm7Q0CTo/L8ALcQFoBHwiGrz33TxvpcPuXYI= github.com/unistack-org/micro-server-tcp/v3 v3.3.0/go.mod h1:3cxrSzkmrHOkWuYvi7dAK+gAsuO6EkxoT9Y0LUNhC3I= github.com/unistack-org/micro-wrapper-trace-opentracing/v3 v3.2.0 h1:PvemkpeCVUWfCoKwt1XmJ8uGK9My/7T29qOVxtYJohw= @@ -499,8 +499,9 @@ github.com/unistack-org/micro/v3 v3.2.24/go.mod h1:iJwCWq2PECMxigfqe6TPC5GLWvj6P github.com/unistack-org/micro/v3 v3.3.0/go.mod h1:iJwCWq2PECMxigfqe6TPC5GLWvj6P94Kk+PTVZGL3w8= github.com/unistack-org/micro/v3 v3.3.10/go.mod h1:5ragE2E8ER5d4FZQJG9pB6qdfOoLXLfKW89l77Dy3jQ= github.com/unistack-org/micro/v3 v3.3.11/go.mod h1:PPCt675o3HPcODFbJ4iRWPmQFAk1WQ+asQSOb/syq6U= -github.com/unistack-org/micro/v3 v3.3.13 h1:y4bDDkbwnjgOckrhFkC6D/o42tr75X33UbrB+Ko0M68= github.com/unistack-org/micro/v3 v3.3.13/go.mod h1:98hNcMXp/WyWJwLwCuwrhN1Jm7aCWaRNsMfRjK8Fq+Y= +github.com/unistack-org/micro/v3 v3.3.14 h1:CAkDMjHZT8/D6GGF5h3gK84m6tlWZC17IGPb2GkAn/4= +github.com/unistack-org/micro/v3 v3.3.14/go.mod h1:ETGcQQUcjxGaD44LUMX+0fgo8Loh7ExldfIPLvfUmDo= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/valyala/fastrand v1.0.0 h1:LUKT9aKer2dVQNUi3waewTbKV+7H17kvWFNKs2ObdkI= diff --git a/server/http/http_test.go b/server/http/http_test.go index 3971f41..f747697 100644 --- a/server/http/http_test.go +++ b/server/http/http_test.go @@ -145,6 +145,15 @@ func (h *Handler) CallDouble(ctx context.Context, req *pb.CallReq, rsp *pb.CallR return nil } +func (h *Handler) CallRepeated(ctx context.Context, req *pb.CallReq, rsp *pb.CallRsp) error { + if len(req.Ids) != 2 || req.Ids[0] != "123" { + h.t.Fatalf("invalid reflect merging") + } + rsp.Rsp = "name_my_name" + httpsrv.SetRspCode(ctx, http.StatusCreated) + return nil +} + func (h *Handler) Call(ctx context.Context, req *pb.CallReq, rsp *pb.CallRsp) error { if req.Nested == nil { h.t.Fatalf("invalid reflect merging") @@ -511,6 +520,41 @@ func TestNativeServer(t *testing.T) { t.Fatalf("Expected response %s, got %s", `{"msg":"my_error"}`, s) } + rsp, err = http.Post(fmt.Sprintf("http://%s/v1/test/call_repeated/?ids=123&ids=321", service[0].Nodes[0].Address), "application/json", nil) + if err != nil { + t.Fatal(err) + } + if rsp.StatusCode != http.StatusCreated { + buf, err := io.ReadAll(rsp.Body) + if err != nil { + t.Fatalf("invalid status received: %#+v err: %v\n", rsp, err) + } + t.Fatalf("invalid status received: %#+v buf: %s\n", rsp, buf) + } + + b, err = ioutil.ReadAll(rsp.Body) + rsp.Body.Close() + + if err != nil { + t.Fatal(err) + } + + if s := string(b); s != `{"rsp":"name_my_name"}` { + t.Fatalf("Expected response %s, got %s", `{"rsp":"name_my_name"}`, s) + } + + c := client.NewClientCallOptions(httpcli.NewClient(client.ContentType("application/json"), client.Codec("application/json", jsoncodec.NewCodec())), client.WithAddress("http://"+service[0].Nodes[0].Address)) + pbc := pb.NewTestClient("test", c) + + prsp, err := pbc.CallRepeated(context.TODO(), &pb.CallReq{Ids: []string{"123", "321"}}) + if err != nil { + t.Fatal(err) + } + + if prsp.Rsp != "name_my_name" { + t.Fatalf("invalid rsp received: %#+v\n", rsp) + } + // stop server if err := srv.Stop(); err != nil { t.Fatal(err) diff --git a/server/http/proto/test.pb.go b/server/http/proto/test.pb.go index 1b28f35..f5dc670 100644 --- a/server/http/proto/test.pb.go +++ b/server/http/proto/test.pb.go @@ -28,11 +28,12 @@ type CallReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Req string `protobuf:"bytes,2,opt,name=req,proto3" json:"req,omitempty"` - Arg1 string `protobuf:"bytes,3,opt,name=arg1,proto3" json:"arg1,omitempty"` - Arg2 uint64 `protobuf:"varint,4,opt,name=arg2,proto3" json:"arg2,omitempty"` - Nested *Nested `protobuf:"bytes,5,opt,name=nested,proto3" json:"nested,omitempty"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Req string `protobuf:"bytes,2,opt,name=req,proto3" json:"req,omitempty"` + Arg1 string `protobuf:"bytes,3,opt,name=arg1,proto3" json:"arg1,omitempty"` + Arg2 uint64 `protobuf:"varint,4,opt,name=arg2,proto3" json:"arg2,omitempty"` + Nested *Nested `protobuf:"bytes,5,opt,name=nested,proto3" json:"nested,omitempty"` + Ids []string `protobuf:"bytes,6,rep,name=ids,proto3" json:"ids,omitempty"` } func (x *CallReq) Reset() { @@ -102,6 +103,13 @@ func (x *CallReq) GetNested() *Nested { return nil } +func (x *CallReq) GetIds() []string { + if x != nil { + return x.Ids + } + return nil +} + type Nested struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -362,61 +370,72 @@ var file_test_proto_rawDesc = []byte{ 0x70, 0x69, 0x76, 0x32, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x77, 0x72, 0x61, 0x70, 0x70, 0x65, 0x72, 0x73, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x7d, 0x0a, 0x07, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, - 0x71, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x65, 0x71, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x03, 0x72, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x72, 0x67, 0x31, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x72, 0x67, 0x31, 0x12, 0x12, 0x0a, 0x04, 0x61, - 0x72, 0x67, 0x32, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x04, 0x61, 0x72, 0x67, 0x32, 0x12, - 0x24, 0x0a, 0x06, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x0c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x52, 0x06, 0x6e, - 0x65, 0x73, 0x74, 0x65, 0x64, 0x22, 0x68, 0x0a, 0x06, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x12, - 0x1f, 0x0a, 0x0b, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x18, 0x01, - 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x41, 0x72, 0x67, 0x73, - 0x12, 0x3d, 0x0a, 0x0b, 0x75, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x18, - 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x55, 0x49, 0x6e, 0x74, 0x36, 0x34, 0x56, 0x61, - 0x6c, 0x75, 0x65, 0x52, 0x0a, 0x75, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x41, 0x72, 0x67, 0x73, 0x22, - 0x1b, 0x0a, 0x07, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x73, - 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x73, 0x70, 0x22, 0x30, 0x0a, 0x08, - 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x31, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, - 0x72, 0x65, 0x71, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x65, 0x71, 0x22, 0x1c, - 0x0a, 0x08, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x31, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x73, - 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x73, 0x70, 0x22, 0x19, 0x0a, 0x05, - 0x45, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x32, 0x97, 0x01, 0x0a, 0x0a, 0x54, 0x65, 0x73, 0x74, - 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x12, 0x88, 0x01, 0x0a, 0x0a, 0x43, 0x61, 0x6c, 0x6c, 0x44, - 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x12, 0x0d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, - 0x6c, 0x52, 0x65, 0x71, 0x1a, 0x0d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, - 0x52, 0x73, 0x70, 0x22, 0x5c, 0x92, 0x41, 0x34, 0x2a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x4a, 0x2c, - 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x21, 0x0a, 0x0e, 0x45, 0x72, 0x72, - 0x6f, 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0f, 0x0a, 0x0d, 0x1a, - 0x0b, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x82, 0xd3, 0xe4, 0x93, - 0x02, 0x1f, 0x22, 0x1a, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x6f, 0x75, 0x62, - 0x6c, 0x65, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x3a, 0x01, - 0x2a, 0x32, 0x94, 0x02, 0x0a, 0x04, 0x54, 0x65, 0x73, 0x74, 0x12, 0x7c, 0x0a, 0x04, 0x43, 0x61, - 0x6c, 0x6c, 0x12, 0x0d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, - 0x71, 0x1a, 0x0d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, - 0x22, 0x56, 0x92, 0x41, 0x34, 0x2a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x4a, 0x2c, 0x0a, 0x07, 0x64, - 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x21, 0x0a, 0x0e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, - 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0f, 0x0a, 0x0d, 0x1a, 0x0b, 0x2e, 0x74, - 0x65, 0x73, 0x74, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x22, - 0x14, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x2f, 0x7b, - 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x3a, 0x01, 0x2a, 0x12, 0x8d, 0x01, 0x0a, 0x09, 0x43, 0x61, 0x6c, - 0x6c, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, - 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x31, 0x1a, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, - 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x31, 0x22, 0x60, 0x92, 0x41, 0x39, 0x2a, 0x09, 0x43, 0x61, 0x6c, - 0x6c, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x4a, 0x2c, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, - 0x74, 0x12, 0x21, 0x0a, 0x0e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x0f, 0x0a, 0x0d, 0x1a, 0x0b, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x45, - 0x72, 0x72, 0x6f, 0x72, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1e, 0x22, 0x19, 0x2f, 0x76, 0x31, 0x2f, - 0x74, 0x65, 0x73, 0x74, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x2f, 0x7b, - 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x3a, 0x01, 0x2a, 0x42, 0x3a, 0x5a, 0x38, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x75, 0x6e, 0x69, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x2d, - 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, - 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x8f, 0x01, 0x0a, 0x07, 0x43, 0x61, 0x6c, 0x6c, 0x52, + 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x65, 0x71, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x72, 0x67, 0x31, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x72, 0x67, 0x31, 0x12, 0x12, 0x0a, 0x04, + 0x61, 0x72, 0x67, 0x32, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x04, 0x61, 0x72, 0x67, 0x32, + 0x12, 0x24, 0x0a, 0x06, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x0c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x52, 0x06, + 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x64, 0x73, 0x18, 0x06, 0x20, + 0x03, 0x28, 0x09, 0x52, 0x03, 0x69, 0x64, 0x73, 0x22, 0x68, 0x0a, 0x06, 0x4e, 0x65, 0x73, 0x74, + 0x65, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, 0x61, 0x72, 0x67, + 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x41, + 0x72, 0x67, 0x73, 0x12, 0x3d, 0x0a, 0x0b, 0x75, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x5f, 0x61, 0x72, + 0x67, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x55, 0x49, 0x6e, 0x74, 0x36, + 0x34, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x0a, 0x75, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x41, 0x72, + 0x67, 0x73, 0x22, 0x1b, 0x0a, 0x07, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x12, 0x10, 0x0a, + 0x03, 0x72, 0x73, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x73, 0x70, 0x22, + 0x30, 0x0a, 0x08, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x31, 0x12, 0x12, 0x0a, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, + 0x10, 0x0a, 0x03, 0x72, 0x65, 0x71, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x65, + 0x71, 0x22, 0x1c, 0x0a, 0x08, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x31, 0x12, 0x10, 0x0a, + 0x03, 0x72, 0x73, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x73, 0x70, 0x22, + 0x19, 0x0a, 0x05, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x32, 0x97, 0x01, 0x0a, 0x0a, 0x54, + 0x65, 0x73, 0x74, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x12, 0x88, 0x01, 0x0a, 0x0a, 0x43, 0x61, + 0x6c, 0x6c, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x12, 0x0d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, + 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x1a, 0x0d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, + 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x22, 0x5c, 0x92, 0x41, 0x34, 0x2a, 0x04, 0x43, 0x61, 0x6c, + 0x6c, 0x4a, 0x2c, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x21, 0x0a, 0x0e, + 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0f, + 0x0a, 0x0d, 0x1a, 0x0b, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x1f, 0x22, 0x1a, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, + 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, + 0x7d, 0x3a, 0x01, 0x2a, 0x32, 0xab, 0x03, 0x0a, 0x04, 0x54, 0x65, 0x73, 0x74, 0x12, 0x94, 0x01, + 0x0a, 0x0c, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x0d, + 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x1a, 0x0d, 0x2e, + 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x22, 0x66, 0x92, 0x41, + 0x3c, 0x2a, 0x0c, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x4a, + 0x2c, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x21, 0x0a, 0x0e, 0x45, 0x72, + 0x72, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0f, 0x0a, 0x0d, + 0x1a, 0x0b, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x21, 0x22, 0x1c, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x63, 0x61, + 0x6c, 0x6c, 0x5f, 0x72, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x2f, 0x7b, 0x69, 0x64, 0x73, + 0x7d, 0x3a, 0x01, 0x2a, 0x12, 0x7c, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x0d, 0x2e, 0x74, + 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x1a, 0x0d, 0x2e, 0x74, 0x65, + 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x22, 0x56, 0x92, 0x41, 0x34, 0x2a, + 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x4a, 0x2c, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, + 0x12, 0x21, 0x0a, 0x0e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x0f, 0x0a, 0x0d, 0x1a, 0x0b, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x72, + 0x72, 0x6f, 0x72, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x22, 0x14, 0x2f, 0x76, 0x31, 0x2f, 0x74, + 0x65, 0x73, 0x74, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x3a, + 0x01, 0x2a, 0x12, 0x8d, 0x01, 0x0a, 0x09, 0x43, 0x61, 0x6c, 0x6c, 0x45, 0x72, 0x72, 0x6f, 0x72, + 0x12, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x31, + 0x1a, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x31, + 0x22, 0x60, 0x92, 0x41, 0x39, 0x2a, 0x09, 0x43, 0x61, 0x6c, 0x6c, 0x45, 0x72, 0x72, 0x6f, 0x72, + 0x4a, 0x2c, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x21, 0x0a, 0x0e, 0x45, + 0x72, 0x72, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0f, 0x0a, + 0x0d, 0x1a, 0x0b, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x1e, 0x22, 0x19, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x63, + 0x61, 0x6c, 0x6c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x3a, + 0x01, 0x2a, 0x42, 0x3a, 0x5a, 0x38, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x75, 0x6e, 0x69, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x2d, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, + 0x63, 0x72, 0x6f, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, + 0x2f, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x70, 0x62, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -445,13 +464,15 @@ var file_test_proto_depIdxs = []int32{ 1, // 0: test.CallReq.nested:type_name -> test.Nested 6, // 1: test.Nested.uint64_args:type_name -> google.protobuf.UInt64Value 0, // 2: test.TestDouble.CallDouble:input_type -> test.CallReq - 0, // 3: test.Test.Call:input_type -> test.CallReq - 3, // 4: test.Test.CallError:input_type -> test.CallReq1 - 2, // 5: test.TestDouble.CallDouble:output_type -> test.CallRsp - 2, // 6: test.Test.Call:output_type -> test.CallRsp - 4, // 7: test.Test.CallError:output_type -> test.CallRsp1 - 5, // [5:8] is the sub-list for method output_type - 2, // [2:5] is the sub-list for method input_type + 0, // 3: test.Test.CallRepeated:input_type -> test.CallReq + 0, // 4: test.Test.Call:input_type -> test.CallReq + 3, // 5: test.Test.CallError:input_type -> test.CallReq1 + 2, // 6: test.TestDouble.CallDouble:output_type -> test.CallRsp + 2, // 7: test.Test.CallRepeated:output_type -> test.CallRsp + 2, // 8: test.Test.Call:output_type -> test.CallRsp + 4, // 9: test.Test.CallError:output_type -> test.CallRsp1 + 6, // [6:10] is the sub-list for method output_type + 2, // [2:6] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name 2, // [2:2] is the sub-list for extension extendee 0, // [0:2] is the sub-list for field type_name diff --git a/server/http/proto/test.proto b/server/http/proto/test.proto index e21cde7..0b2381c 100644 --- a/server/http/proto/test.proto +++ b/server/http/proto/test.proto @@ -31,6 +31,25 @@ service TestDouble { }; service Test { + rpc CallRepeated(CallReq) returns (CallRsp) { + option (micro.openapiv2.openapiv2_operation) = { + operation_id: "CallRepeated"; + responses: { + key: "default"; + value: { + description: "Error response"; + schema: { + json_schema: { + ref: ".test.Error"; + } + } + } + } + }; + option (micro.api.http) = { post: "/v1/test/call_repeated/{ids}"; body: "*"; }; + //option (micro.api.micro_method) = { timeout: 5; }; + }; + //option (micro.api.micro_service) = { client_wrappers: ["one","two"]; }; rpc Call(CallReq) returns (CallRsp) { option (micro.openapiv2.openapiv2_operation) = { @@ -76,6 +95,7 @@ message CallReq { string arg1 = 3; uint64 arg2 = 4; Nested nested = 5; + repeated string ids = 6; }; message Nested { diff --git a/server/http/proto/test_micro.pb.go b/server/http/proto/test_micro.pb.go index d09196e..9cc3872 100644 --- a/server/http/proto/test_micro.pb.go +++ b/server/http/proto/test_micro.pb.go @@ -30,6 +30,13 @@ type TestDoubleServer interface { func NewTestEndpoints() []*api.Endpoint { return []*api.Endpoint{ + &api.Endpoint{ + Name: "Test.CallRepeated", + Path: []string{"/v1/test/call_repeated/{ids}"}, + Method: []string{"POST"}, + Body: "*", + Handler: "rpc", + }, &api.Endpoint{ Name: "Test.Call", Path: []string{"/v1/test/call/{name}"}, @@ -48,11 +55,13 @@ func NewTestEndpoints() []*api.Endpoint { } type TestClient interface { + CallRepeated(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error) Call(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error) CallError(ctx context.Context, req *CallReq1, opts ...client.CallOption) (*CallRsp1, error) } type TestServer interface { + CallRepeated(ctx context.Context, req *CallReq, rsp *CallRsp) error Call(ctx context.Context, req *CallReq, rsp *CallRsp) error CallError(ctx context.Context, req *CallReq1, rsp *CallRsp1) error } diff --git a/server/http/proto/test_micro_http.pb.go b/server/http/proto/test_micro_http.pb.go index b8ac6b6..d5ddcea 100644 --- a/server/http/proto/test_micro_http.pb.go +++ b/server/http/proto/test_micro_http.pb.go @@ -8,6 +8,7 @@ import ( api "github.com/unistack-org/micro/v3/api" client "github.com/unistack-org/micro/v3/client" server "github.com/unistack-org/micro/v3/server" + http "net/http" ) type testDoubleClient struct { @@ -26,7 +27,7 @@ func (c *testDoubleClient) CallDouble(ctx context.Context, req *CallReq, opts .. v3.ErrorMap(errmap), ) opts = append(opts, - v3.Method("POST"), + v3.Method(http.MethodPost), v3.Path("/v1/testdouble/call/{name}"), v3.Body("*"), ) @@ -54,10 +55,11 @@ func RegisterTestDoubleServer(s server.Server, sh TestDoubleServer, opts ...serv testDouble } h := &testDoubleServer{sh} + var nopts []server.HandlerOption for _, endpoint := range NewTestDoubleEndpoints() { - opts = append(opts, api.WithEndpoint(endpoint)) + nopts = append(nopts, api.WithEndpoint(endpoint)) } - return s.Handle(s.NewHandler(&TestDouble{h}, opts...)) + return s.Handle(s.NewHandler(&TestDouble{h}, append(nopts, opts...)...)) } type testClient struct { @@ -69,6 +71,25 @@ func NewTestClient(name string, c client.Client) TestClient { return &testClient{c: c, name: name} } +func (c *testClient) CallRepeated(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error) { + errmap := make(map[string]interface{}, 1) + errmap["default"] = &Error{} + opts = append(opts, + v3.ErrorMap(errmap), + ) + opts = append(opts, + v3.Method(http.MethodPost), + v3.Path("/v1/test/call_repeated/{ids}"), + v3.Body("*"), + ) + rsp := &CallRsp{} + err := c.c.Call(ctx, c.c.NewRequest(c.name, "Test.CallRepeated", req), rsp, opts...) + if err != nil { + return nil, err + } + return rsp, nil +} + func (c *testClient) Call(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error) { errmap := make(map[string]interface{}, 1) errmap["default"] = &Error{} @@ -76,7 +97,7 @@ func (c *testClient) Call(ctx context.Context, req *CallReq, opts ...client.Call v3.ErrorMap(errmap), ) opts = append(opts, - v3.Method("POST"), + v3.Method(http.MethodPost), v3.Path("/v1/test/call/{name}"), v3.Body("*"), ) @@ -95,7 +116,7 @@ func (c *testClient) CallError(ctx context.Context, req *CallReq1, opts ...clien v3.ErrorMap(errmap), ) opts = append(opts, - v3.Method("POST"), + v3.Method(http.MethodPost), v3.Path("/v1/test/callerror/{name}"), v3.Body("*"), ) @@ -111,6 +132,10 @@ type testServer struct { TestServer } +func (h *testServer) CallRepeated(ctx context.Context, req *CallReq, rsp *CallRsp) error { + return h.TestServer.CallRepeated(ctx, req, rsp) +} + func (h *testServer) Call(ctx context.Context, req *CallReq, rsp *CallRsp) error { return h.TestServer.Call(ctx, req, rsp) } @@ -121,6 +146,7 @@ func (h *testServer) CallError(ctx context.Context, req *CallReq1, rsp *CallRsp1 func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOption) error { type test interface { + CallRepeated(ctx context.Context, req *CallReq, rsp *CallRsp) error Call(ctx context.Context, req *CallReq, rsp *CallRsp) error CallError(ctx context.Context, req *CallReq1, rsp *CallRsp1) error } @@ -128,8 +154,9 @@ func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOp test } h := &testServer{sh} + var nopts []server.HandlerOption for _, endpoint := range NewTestEndpoints() { - opts = append(opts, api.WithEndpoint(endpoint)) + nopts = append(nopts, api.WithEndpoint(endpoint)) } - return s.Handle(s.NewHandler(&Test{h}, opts...)) + return s.Handle(s.NewHandler(&Test{h}, append(nopts, opts...)...)) }