http/binding: rename encode url (#1039)

* rename binding url
pull/1040/head
Tony Chen 4 years ago committed by GitHub
parent eca0f35cb5
commit 2729caeecf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      api/metadata/metadata_http.pb.go
  2. 2
      cmd/protoc-gen-go-http/http.go
  3. 2
      cmd/protoc-gen-go-http/template.go
  4. 12
      examples/blog/api/blog/v1/blog_http.pb.go
  5. 4
      examples/helloworld/helloworld/helloworld_http.pb.go
  6. 4
      examples/traces/api/message/message_http.pb.go
  7. 4
      examples/traces/api/user/user_http.pb.go
  8. 12
      internal/testproto/echo_service_http.pb.go
  9. 34
      transport/http/binding/encode.go
  10. 8
      transport/http/binding/proto_test.go

@ -15,7 +15,7 @@ import (
// is compatible with the kratos package it is being compiled against. // is compatible with the kratos package it is being compiled against.
var _ = new(context.Context) var _ = new(context.Context)
var _ = new(transport.Transporter) var _ = new(transport.Transporter)
var _ = binding.EncodeVars var _ = binding.EncodeURL
const _ = http.SupportPackageIsVersion1 const _ = http.SupportPackageIsVersion1
@ -86,7 +86,7 @@ func NewMetadataHTTPClient(client *http.Client) MetadataHTTPClient {
func (c *MetadataHTTPClientImpl) GetServiceDesc(ctx context.Context, in *GetServiceDescRequest, opts ...http.CallOption) (*GetServiceDescReply, error) { func (c *MetadataHTTPClientImpl) GetServiceDesc(ctx context.Context, in *GetServiceDescRequest, opts ...http.CallOption) (*GetServiceDescReply, error) {
var out GetServiceDescReply var out GetServiceDescReply
path := binding.EncodeVars("/services/{name}", in, true) path := binding.EncodeURL("/services/{name}", in, true)
opts = append(opts, http.Operation("/kratos.api.Metadata/GetServiceDesc")) opts = append(opts, http.Operation("/kratos.api.Metadata/GetServiceDesc"))
err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...)
if err != nil { if err != nil {
@ -97,7 +97,7 @@ func (c *MetadataHTTPClientImpl) GetServiceDesc(ctx context.Context, in *GetServ
func (c *MetadataHTTPClientImpl) ListServices(ctx context.Context, in *ListServicesRequest, opts ...http.CallOption) (*ListServicesReply, error) { func (c *MetadataHTTPClientImpl) ListServices(ctx context.Context, in *ListServicesRequest, opts ...http.CallOption) (*ListServicesReply, error) {
var out ListServicesReply var out ListServicesReply
path := binding.EncodeVars("/services", in, true) path := binding.EncodeURL("/services", in, true)
opts = append(opts, http.Operation("/kratos.api.Metadata/ListServices")) opts = append(opts, http.Operation("/kratos.api.Metadata/ListServices"))
err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...)
if err != nil { if err != nil {

@ -45,7 +45,7 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen.
g.P("// is compatible with the kratos package it is being compiled against.") g.P("// is compatible with the kratos package it is being compiled against.")
g.P("var _ = new(", contextPackage.Ident("Context"), ")") g.P("var _ = new(", contextPackage.Ident("Context"), ")")
g.P("var _ = new(", transportPackage.Ident("Transporter"), ")") g.P("var _ = new(", transportPackage.Ident("Transporter"), ")")
g.P("var _ = ", bindingPackage.Ident("EncodeVars")) g.P("var _ = ", bindingPackage.Ident("EncodeURL"))
g.P("const _ = ", transportHTTPPackage.Ident("SupportPackageIsVersion1")) g.P("const _ = ", transportHTTPPackage.Ident("SupportPackageIsVersion1"))
g.P() g.P()

@ -65,7 +65,7 @@ func New{{.ServiceType}}HTTPClient (client *http.Client) {{.ServiceType}}HTTPCli
{{range .MethodSets}} {{range .MethodSets}}
func (c *{{$svrType}}HTTPClientImpl) {{.Name}}(ctx context.Context, in *{{.Request}}, opts ...http.CallOption) (*{{.Reply}}, error) { func (c *{{$svrType}}HTTPClientImpl) {{.Name}}(ctx context.Context, in *{{.Request}}, opts ...http.CallOption) (*{{.Reply}}, error) {
var out {{.Reply}} var out {{.Reply}}
path := binding.EncodeVars("{{.Path}}", in, {{.IsQuery}}) path := binding.EncodeURL("{{.Path}}", in, {{.IsQuery}})
opts = append(opts, http.Operation("/{{$svrName}}/{{.Name}}")) opts = append(opts, http.Operation("/{{$svrName}}/{{.Name}}"))
{{if .HasBody -}} {{if .HasBody -}}
err := c.cc.Invoke(ctx, "{{.Method}}", path, in{{.Body}}, &out{{.ResponseBody}}, opts...) err := c.cc.Invoke(ctx, "{{.Method}}", path, in{{.Body}}, &out{{.ResponseBody}}, opts...)

@ -15,7 +15,7 @@ import (
// is compatible with the kratos package it is being compiled against. // is compatible with the kratos package it is being compiled against.
var _ = new(context.Context) var _ = new(context.Context)
var _ = new(transport.Transporter) var _ = new(transport.Transporter)
var _ = binding.EncodeVars var _ = binding.EncodeURL
const _ = http.SupportPackageIsVersion1 const _ = http.SupportPackageIsVersion1
@ -158,7 +158,7 @@ func NewBlogServiceHTTPClient(client *http.Client) BlogServiceHTTPClient {
func (c *BlogServiceHTTPClientImpl) CreateArticle(ctx context.Context, in *CreateArticleRequest, opts ...http.CallOption) (*CreateArticleReply, error) { func (c *BlogServiceHTTPClientImpl) CreateArticle(ctx context.Context, in *CreateArticleRequest, opts ...http.CallOption) (*CreateArticleReply, error) {
var out CreateArticleReply var out CreateArticleReply
path := binding.EncodeVars("/v1/article/", in, false) path := binding.EncodeURL("/v1/article/", in, false)
opts = append(opts, http.Operation("/blog.api.v1.BlogService/CreateArticle")) opts = append(opts, http.Operation("/blog.api.v1.BlogService/CreateArticle"))
err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...)
if err != nil { if err != nil {
@ -169,7 +169,7 @@ func (c *BlogServiceHTTPClientImpl) CreateArticle(ctx context.Context, in *Creat
func (c *BlogServiceHTTPClientImpl) DeleteArticle(ctx context.Context, in *DeleteArticleRequest, opts ...http.CallOption) (*DeleteArticleReply, error) { func (c *BlogServiceHTTPClientImpl) DeleteArticle(ctx context.Context, in *DeleteArticleRequest, opts ...http.CallOption) (*DeleteArticleReply, error) {
var out DeleteArticleReply var out DeleteArticleReply
path := binding.EncodeVars("/v1/article/{id}", in, false) path := binding.EncodeURL("/v1/article/{id}", in, false)
opts = append(opts, http.Operation("/blog.api.v1.BlogService/DeleteArticle")) opts = append(opts, http.Operation("/blog.api.v1.BlogService/DeleteArticle"))
err := c.cc.Invoke(ctx, "DELETE", path, nil, &out, opts...) err := c.cc.Invoke(ctx, "DELETE", path, nil, &out, opts...)
if err != nil { if err != nil {
@ -180,7 +180,7 @@ func (c *BlogServiceHTTPClientImpl) DeleteArticle(ctx context.Context, in *Delet
func (c *BlogServiceHTTPClientImpl) GetArticle(ctx context.Context, in *GetArticleRequest, opts ...http.CallOption) (*GetArticleReply, error) { func (c *BlogServiceHTTPClientImpl) GetArticle(ctx context.Context, in *GetArticleRequest, opts ...http.CallOption) (*GetArticleReply, error) {
var out GetArticleReply var out GetArticleReply
path := binding.EncodeVars("/v1/article/{id}", in, true) path := binding.EncodeURL("/v1/article/{id}", in, true)
opts = append(opts, http.Operation("/blog.api.v1.BlogService/GetArticle")) opts = append(opts, http.Operation("/blog.api.v1.BlogService/GetArticle"))
err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...)
if err != nil { if err != nil {
@ -191,7 +191,7 @@ func (c *BlogServiceHTTPClientImpl) GetArticle(ctx context.Context, in *GetArtic
func (c *BlogServiceHTTPClientImpl) ListArticle(ctx context.Context, in *ListArticleRequest, opts ...http.CallOption) (*ListArticleReply, error) { func (c *BlogServiceHTTPClientImpl) ListArticle(ctx context.Context, in *ListArticleRequest, opts ...http.CallOption) (*ListArticleReply, error) {
var out ListArticleReply var out ListArticleReply
path := binding.EncodeVars("/v1/article/", in, true) path := binding.EncodeURL("/v1/article/", in, true)
opts = append(opts, http.Operation("/blog.api.v1.BlogService/ListArticle")) opts = append(opts, http.Operation("/blog.api.v1.BlogService/ListArticle"))
err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...)
if err != nil { if err != nil {
@ -202,7 +202,7 @@ func (c *BlogServiceHTTPClientImpl) ListArticle(ctx context.Context, in *ListArt
func (c *BlogServiceHTTPClientImpl) UpdateArticle(ctx context.Context, in *UpdateArticleRequest, opts ...http.CallOption) (*UpdateArticleReply, error) { func (c *BlogServiceHTTPClientImpl) UpdateArticle(ctx context.Context, in *UpdateArticleRequest, opts ...http.CallOption) (*UpdateArticleReply, error) {
var out UpdateArticleReply var out UpdateArticleReply
path := binding.EncodeVars("/v1/article/{id}", in, false) path := binding.EncodeURL("/v1/article/{id}", in, false)
opts = append(opts, http.Operation("/blog.api.v1.BlogService/UpdateArticle")) opts = append(opts, http.Operation("/blog.api.v1.BlogService/UpdateArticle"))
err := c.cc.Invoke(ctx, "PUT", path, in, &out, opts...) err := c.cc.Invoke(ctx, "PUT", path, in, &out, opts...)
if err != nil { if err != nil {

@ -15,7 +15,7 @@ import (
// is compatible with the kratos package it is being compiled against. // is compatible with the kratos package it is being compiled against.
var _ = new(context.Context) var _ = new(context.Context)
var _ = new(transport.Transporter) var _ = new(transport.Transporter)
var _ = binding.EncodeVars var _ = binding.EncodeURL
const _ = http.SupportPackageIsVersion1 const _ = http.SupportPackageIsVersion1
@ -64,7 +64,7 @@ func NewGreeterHTTPClient(client *http.Client) GreeterHTTPClient {
func (c *GreeterHTTPClientImpl) SayHello(ctx context.Context, in *HelloRequest, opts ...http.CallOption) (*HelloReply, error) { func (c *GreeterHTTPClientImpl) SayHello(ctx context.Context, in *HelloRequest, opts ...http.CallOption) (*HelloReply, error) {
var out HelloReply var out HelloReply
path := binding.EncodeVars("/helloworld/{name}", in, true) path := binding.EncodeURL("/helloworld/{name}", in, true)
opts = append(opts, http.Operation("/helloworld.Greeter/SayHello")) opts = append(opts, http.Operation("/helloworld.Greeter/SayHello"))
err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...)
if err != nil { if err != nil {

@ -15,7 +15,7 @@ import (
// is compatible with the kratos package it is being compiled against. // is compatible with the kratos package it is being compiled against.
var _ = new(context.Context) var _ = new(context.Context)
var _ = new(transport.Transporter) var _ = new(transport.Transporter)
var _ = binding.EncodeVars var _ = binding.EncodeURL
const _ = http.SupportPackageIsVersion1 const _ = http.SupportPackageIsVersion1
@ -64,7 +64,7 @@ func NewMessageServiceHTTPClient(client *http.Client) MessageServiceHTTPClient {
func (c *MessageServiceHTTPClientImpl) GetUserMessage(ctx context.Context, in *GetUserMessageRequest, opts ...http.CallOption) (*GetUserMessageReply, error) { func (c *MessageServiceHTTPClientImpl) GetUserMessage(ctx context.Context, in *GetUserMessageRequest, opts ...http.CallOption) (*GetUserMessageReply, error) {
var out GetUserMessageReply var out GetUserMessageReply
path := binding.EncodeVars("/v1/message/user/{id}/{count}", in, true) path := binding.EncodeURL("/v1/message/user/{id}/{count}", in, true)
opts = append(opts, http.Operation("/api.message.v1.MessageService/GetUserMessage")) opts = append(opts, http.Operation("/api.message.v1.MessageService/GetUserMessage"))
err := c.cc.Invoke(ctx, "GET", path, in, &out, opts...) err := c.cc.Invoke(ctx, "GET", path, in, &out, opts...)
if err != nil { if err != nil {

@ -15,7 +15,7 @@ import (
// is compatible with the kratos package it is being compiled against. // is compatible with the kratos package it is being compiled against.
var _ = new(context.Context) var _ = new(context.Context)
var _ = new(transport.Transporter) var _ = new(transport.Transporter)
var _ = binding.EncodeVars var _ = binding.EncodeURL
const _ = http.SupportPackageIsVersion1 const _ = http.SupportPackageIsVersion1
@ -64,7 +64,7 @@ func NewUserHTTPClient(client *http.Client) UserHTTPClient {
func (c *UserHTTPClientImpl) GetMyMessages(ctx context.Context, in *GetMyMessagesRequest, opts ...http.CallOption) (*GetMyMessagesReply, error) { func (c *UserHTTPClientImpl) GetMyMessages(ctx context.Context, in *GetMyMessagesRequest, opts ...http.CallOption) (*GetMyMessagesReply, error) {
var out GetMyMessagesReply var out GetMyMessagesReply
path := binding.EncodeVars("/v1/user/get/message/{count}", in, true) path := binding.EncodeURL("/v1/user/get/message/{count}", in, true)
opts = append(opts, http.Operation("/api.user.v1.User/GetMyMessages")) opts = append(opts, http.Operation("/api.user.v1.User/GetMyMessages"))
err := c.cc.Invoke(ctx, "GET", path, in, &out, opts...) err := c.cc.Invoke(ctx, "GET", path, in, &out, opts...)
if err != nil { if err != nil {

@ -15,7 +15,7 @@ import (
// is compatible with the kratos package it is being compiled against. // is compatible with the kratos package it is being compiled against.
var _ = new(context.Context) var _ = new(context.Context)
var _ = new(transport.Transporter) var _ = new(transport.Transporter)
var _ = binding.EncodeVars var _ = binding.EncodeURL
const _ = http.SupportPackageIsVersion1 const _ = http.SupportPackageIsVersion1
@ -247,7 +247,7 @@ func NewEchoServiceHTTPClient(client *http.Client) EchoServiceHTTPClient {
func (c *EchoServiceHTTPClientImpl) Echo(ctx context.Context, in *SimpleMessage, opts ...http.CallOption) (*SimpleMessage, error) { func (c *EchoServiceHTTPClientImpl) Echo(ctx context.Context, in *SimpleMessage, opts ...http.CallOption) (*SimpleMessage, error) {
var out SimpleMessage var out SimpleMessage
path := binding.EncodeVars("/v1/example/echo/{id}", in, false) path := binding.EncodeURL("/v1/example/echo/{id}", in, false)
opts = append(opts, http.Operation("/testproto.EchoService/Echo")) opts = append(opts, http.Operation("/testproto.EchoService/Echo"))
err := c.cc.Invoke(ctx, "POST", path, nil, &out, opts...) err := c.cc.Invoke(ctx, "POST", path, nil, &out, opts...)
if err != nil { if err != nil {
@ -258,7 +258,7 @@ func (c *EchoServiceHTTPClientImpl) Echo(ctx context.Context, in *SimpleMessage,
func (c *EchoServiceHTTPClientImpl) EchoBody(ctx context.Context, in *SimpleMessage, opts ...http.CallOption) (*SimpleMessage, error) { func (c *EchoServiceHTTPClientImpl) EchoBody(ctx context.Context, in *SimpleMessage, opts ...http.CallOption) (*SimpleMessage, error) {
var out SimpleMessage var out SimpleMessage
path := binding.EncodeVars("/v1/example/echo_body", in, false) path := binding.EncodeURL("/v1/example/echo_body", in, false)
opts = append(opts, http.Operation("/testproto.EchoService/EchoBody")) opts = append(opts, http.Operation("/testproto.EchoService/EchoBody"))
err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...)
if err != nil { if err != nil {
@ -269,7 +269,7 @@ func (c *EchoServiceHTTPClientImpl) EchoBody(ctx context.Context, in *SimpleMess
func (c *EchoServiceHTTPClientImpl) EchoDelete(ctx context.Context, in *SimpleMessage, opts ...http.CallOption) (*SimpleMessage, error) { func (c *EchoServiceHTTPClientImpl) EchoDelete(ctx context.Context, in *SimpleMessage, opts ...http.CallOption) (*SimpleMessage, error) {
var out SimpleMessage var out SimpleMessage
path := binding.EncodeVars("/v1/example/echo_delete/{id}/{num}", in, false) path := binding.EncodeURL("/v1/example/echo_delete/{id}/{num}", in, false)
opts = append(opts, http.Operation("/testproto.EchoService/EchoDelete")) opts = append(opts, http.Operation("/testproto.EchoService/EchoDelete"))
err := c.cc.Invoke(ctx, "DELETE", path, nil, &out, opts...) err := c.cc.Invoke(ctx, "DELETE", path, nil, &out, opts...)
if err != nil { if err != nil {
@ -280,7 +280,7 @@ func (c *EchoServiceHTTPClientImpl) EchoDelete(ctx context.Context, in *SimpleMe
func (c *EchoServiceHTTPClientImpl) EchoPatch(ctx context.Context, in *DynamicMessageUpdate, opts ...http.CallOption) (*DynamicMessageUpdate, error) { func (c *EchoServiceHTTPClientImpl) EchoPatch(ctx context.Context, in *DynamicMessageUpdate, opts ...http.CallOption) (*DynamicMessageUpdate, error) {
var out DynamicMessageUpdate var out DynamicMessageUpdate
path := binding.EncodeVars("/v1/example/echo_patch", in, false) path := binding.EncodeURL("/v1/example/echo_patch", in, false)
opts = append(opts, http.Operation("/testproto.EchoService/EchoPatch")) opts = append(opts, http.Operation("/testproto.EchoService/EchoPatch"))
err := c.cc.Invoke(ctx, "PATCH", path, in.Body, &out, opts...) err := c.cc.Invoke(ctx, "PATCH", path, in.Body, &out, opts...)
if err != nil { if err != nil {
@ -291,7 +291,7 @@ func (c *EchoServiceHTTPClientImpl) EchoPatch(ctx context.Context, in *DynamicMe
func (c *EchoServiceHTTPClientImpl) EchoResponseBody(ctx context.Context, in *DynamicMessageUpdate, opts ...http.CallOption) (*DynamicMessageUpdate, error) { func (c *EchoServiceHTTPClientImpl) EchoResponseBody(ctx context.Context, in *DynamicMessageUpdate, opts ...http.CallOption) (*DynamicMessageUpdate, error) {
var out DynamicMessageUpdate var out DynamicMessageUpdate
path := binding.EncodeVars("/v1/example/echo_response_body", in, false) path := binding.EncodeURL("/v1/example/echo_response_body", in, false)
opts = append(opts, http.Operation("/testproto.EchoService/EchoResponseBody")) opts = append(opts, http.Operation("/testproto.EchoService/EchoResponseBody"))
err := c.cc.Invoke(ctx, "POST", path, in, &out.Body, opts...) err := c.cc.Invoke(ctx, "POST", path, in, &out.Body, opts...)
if err != nil { if err != nil {

@ -18,8 +18,8 @@ import (
"google.golang.org/protobuf/types/known/wrapperspb" "google.golang.org/protobuf/types/known/wrapperspb"
) )
// EncodeVars binds proto message to url path // EncodeURL encode proto message to url path.
func EncodeVars(pathPattern string, msg proto.Message, isQuery bool) string { func EncodeURL(pathPattern string, msg proto.Message, needQuery bool) string {
if msg == nil || (reflect.ValueOf(msg).Kind() == reflect.Ptr && reflect.ValueOf(msg).IsNil()) { if msg == nil || (reflect.ValueOf(msg).Kind() == reflect.Ptr && reflect.ValueOf(msg).IsNil()) {
return pathPattern return pathPattern
} }
@ -40,8 +40,8 @@ func EncodeVars(pathPattern string, msg proto.Message, isQuery bool) string {
} }
return in return in
}) })
if isQuery { if needQuery {
u, err := encodeQuery(msg) u, err := EncodeQuery(msg)
if err == nil && len(u) > 0 { if err == nil && len(u) > 0 {
for key := range pathParams { for key := range pathParams {
delete(u, key) delete(u, key)
@ -52,10 +52,22 @@ func EncodeVars(pathPattern string, msg proto.Message, isQuery bool) string {
} }
} }
} }
return path return path
} }
// EncodeQuery encode proto message to url query.
func EncodeQuery(msg proto.Message) (url.Values, error) {
if msg == nil || (reflect.ValueOf(msg).Kind() == reflect.Ptr && reflect.ValueOf(msg).IsNil()) {
return url.Values{}, nil
}
u := make(url.Values)
err := encodeByField(u, "", msg.ProtoReflect())
if err != nil {
return nil, err
}
return u, nil
}
func getValueByField(v protoreflect.Message, fieldPath []string) (string, error) { func getValueByField(v protoreflect.Message, fieldPath []string) (string, error) {
var fd protoreflect.FieldDescriptor var fd protoreflect.FieldDescriptor
for i, fieldName := range fieldPath { for i, fieldName := range fieldPath {
@ -77,18 +89,6 @@ func getValueByField(v protoreflect.Message, fieldPath []string) (string, error)
return encodeField(fd, v.Get(fd)) return encodeField(fd, v.Get(fd))
} }
func encodeQuery(msg proto.Message) (url.Values, error) {
if msg == nil || (reflect.ValueOf(msg).Kind() == reflect.Ptr && reflect.ValueOf(msg).IsNil()) {
return url.Values{}, nil
}
u := make(url.Values)
err := encodeByField(u, "", msg.ProtoReflect())
if err != nil {
return nil, err
}
return u, nil
}
func encodeByField(u url.Values, path string, v protoreflect.Message) error { func encodeByField(u url.Values, path string, v protoreflect.Message) error {
for i := 0; i < v.Descriptor().Fields().Len(); i++ { for i := 0; i < v.Descriptor().Fields().Len(); i++ {
fd := v.Descriptor().Fields().Get(i) fd := v.Descriptor().Fields().Get(i)

@ -6,25 +6,25 @@ import (
) )
func TestProtoPath(t *testing.T) { func TestProtoPath(t *testing.T) {
url := EncodeVars("http://helloworld.Greeter/helloworld/{name}/sub/{sub.name}", &HelloRequest{Name: "test", Sub: &Sub{Name: "2233!!!"}}, false) url := EncodeURL("http://helloworld.Greeter/helloworld/{name}/sub/{sub.name}", &HelloRequest{Name: "test", Sub: &Sub{Name: "2233!!!"}}, false)
fmt.Println(url) fmt.Println(url)
if url != `http://helloworld.Greeter/helloworld/test/sub/2233!!!` { if url != `http://helloworld.Greeter/helloworld/test/sub/2233!!!` {
t.Fatalf("proto path not expected!actual: %s ", url) t.Fatalf("proto path not expected!actual: %s ", url)
} }
url = EncodeVars("http://helloworld.Greeter/helloworld/sub", &HelloRequest{Name: "test", Sub: &Sub{Name: "2233!!!"}}, false) url = EncodeURL("http://helloworld.Greeter/helloworld/sub", &HelloRequest{Name: "test", Sub: &Sub{Name: "2233!!!"}}, false)
fmt.Println(url) fmt.Println(url)
if url != `http://helloworld.Greeter/helloworld/sub` { if url != `http://helloworld.Greeter/helloworld/sub` {
t.Fatalf("proto path not expected!actual: %s ", url) t.Fatalf("proto path not expected!actual: %s ", url)
} }
url = EncodeVars("http://helloworld.Greeter/helloworld/{name}/sub/{sub.name}", &HelloRequest{Name: "test"}, false) url = EncodeURL("http://helloworld.Greeter/helloworld/{name}/sub/{sub.name}", &HelloRequest{Name: "test"}, false)
fmt.Println(url) fmt.Println(url)
if url != `http://helloworld.Greeter/helloworld/test/sub/` { if url != `http://helloworld.Greeter/helloworld/test/sub/` {
t.Fatalf("proto path not expected!actual: %s ", url) t.Fatalf("proto path not expected!actual: %s ", url)
} }
url = EncodeVars("http://helloworld.Greeter/helloworld/{name}/sub/{sub.name33}", &HelloRequest{Name: "test"}, false) url = EncodeURL("http://helloworld.Greeter/helloworld/{name}/sub/{sub.name33}", &HelloRequest{Name: "test"}, false)
fmt.Println(url) fmt.Println(url)
if url != `http://helloworld.Greeter/helloworld/test/sub/{sub.name33}` { if url != `http://helloworld.Greeter/helloworld/test/sub/{sub.name33}` {
t.Fatalf("proto path not expected!actual: %s ", url) t.Fatalf("proto path not expected!actual: %s ", url)

Loading…
Cancel
Save