diff --git a/protoc-gen-grpc-gateway/descriptor/services.go b/protoc-gen-grpc-gateway/descriptor/services.go index e054925efec..3f324d294a9 100644 --- a/protoc-gen-grpc-gateway/descriptor/services.go +++ b/protoc-gen-grpc-gateway/descriptor/services.go @@ -183,7 +183,7 @@ func extractAPIOptions(meth *descriptor.MethodDescriptorProto) (*options.HttpRul func (r *Registry) newParam(meth *Method, path string) (Parameter, error) { msg := meth.RequestType - fields, err := r.resolveFiledPath(msg, path) + fields, err := r.resolveFieldPath(msg, path) if err != nil { return Parameter{}, err } @@ -216,7 +216,7 @@ func (r *Registry) newBody(meth *Method, path string) (*Body, error) { case "*": return &Body{FieldPath: nil}, nil } - fields, err := r.resolveFiledPath(msg, path) + fields, err := r.resolveFieldPath(msg, path) if err != nil { return nil, err } @@ -235,7 +235,7 @@ func lookupField(msg *Message, name string) *Field { } // resolveFieldPath resolves "path" into a list of fieldDescriptor, starting from "msg". -func (r *Registry) resolveFiledPath(msg *Message, path string) ([]FieldPathComponent, error) { +func (r *Registry) resolveFieldPath(msg *Message, path string) ([]FieldPathComponent, error) { if path == "" { return nil, nil } diff --git a/protoc-gen-grpc-gateway/descriptor/services_test.go b/protoc-gen-grpc-gateway/descriptor/services_test.go index eda34d4141e..93a8f67ce05 100644 --- a/protoc-gen-grpc-gateway/descriptor/services_test.go +++ b/protoc-gen-grpc-gateway/descriptor/services_test.go @@ -1097,7 +1097,7 @@ func TestResolveFieldPath(t *testing.T) { if err != nil { t.Fatalf("reg.LookupFile(%q) failed with %v; want success; on file=%s", file.GetName(), err, spec.src) } - _, err = reg.resolveFiledPath(f.Messages[0], spec.path) + _, err = reg.resolveFieldPath(f.Messages[0], spec.path) if got, want := err != nil, spec.wantErr; got != want { if want { t.Errorf("reg.resolveFiledPath(%q, %q) succeeded; want an error", f.Messages[0].GetName(), spec.path) diff --git a/protoc-gen-grpc-gateway/descriptor/types.go b/protoc-gen-grpc-gateway/descriptor/types.go index 88dff7bb902..bfdb2dc81d9 100644 --- a/protoc-gen-grpc-gateway/descriptor/types.go +++ b/protoc-gen-grpc-gateway/descriptor/types.go @@ -216,10 +216,10 @@ type Body struct { FieldPath FieldPath } -// RHS returns a right-hand-side expression in go to be used to initialize method request object. +// AssignableExpr returns an assignable expression in Go to be used to initialize method request object. // It starts with "msgExpr", which is the go expression of the method request object. -func (b Body) RHS(msgExpr string) string { - return b.FieldPath.RHS(msgExpr) +func (b Body) AssignableExpr(msgExpr string) string { + return b.FieldPath.AssignableExpr(msgExpr) } // FieldPath is a path to a field from a request message. @@ -242,9 +242,9 @@ func (p FieldPath) IsNestedProto3() bool { return false } -// RHS is a right-hand-side expression in go to be used to assign a value to the target field. +// AssignableExpr is an assignable expression in Go to be used to assign a value to the target field. // It starts with "msgExpr", which is the go expression of the method request object. -func (p FieldPath) RHS(msgExpr string) string { +func (p FieldPath) AssignableExpr(msgExpr string) string { l := len(p) if l == 0 { return msgExpr @@ -252,10 +252,10 @@ func (p FieldPath) RHS(msgExpr string) string { components := []string{msgExpr} for i, c := range p { if i == l-1 { - components = append(components, c.RHS()) + components = append(components, c.AssignableExpr()) continue } - components = append(components, c.LHS()) + components = append(components, c.ValueExpr()) } return strings.Join(components, ".") } @@ -269,13 +269,13 @@ type FieldPathComponent struct { Target *Field } -// RHS returns a right-hand-side expression in go for this field. -func (c FieldPathComponent) RHS() string { +// AssignableExpr returns an assignable expression in go for this field. +func (c FieldPathComponent) AssignableExpr() string { return gogen.CamelCase(c.Name) } -// LHS returns a left-hand-side expression in go for this field. -func (c FieldPathComponent) LHS() string { +// ValueExpr returns an expression in go for this field. +func (c FieldPathComponent) ValueExpr() string { if c.Target.Message.File.proto2() { return fmt.Sprintf("Get%s()", gogen.CamelCase(c.Name)) } diff --git a/protoc-gen-grpc-gateway/descriptor/types_test.go b/protoc-gen-grpc-gateway/descriptor/types_test.go index ef2162a61fb..1dcdb341ef6 100644 --- a/protoc-gen-grpc-gateway/descriptor/types_test.go +++ b/protoc-gen-grpc-gateway/descriptor/types_test.go @@ -161,22 +161,22 @@ func TestFieldPath(t *testing.T) { Name: "nest_field", Target: nest2.Fields[0], } - if got, want := c1.LHS(), "GetNestField()"; got != want { - t.Errorf("c1.LHS() = %q; want %q", got, want) + if got, want := c1.ValueExpr(), "GetNestField()"; got != want { + t.Errorf("c1.ValueExpr() = %q; want %q", got, want) } - if got, want := c1.RHS(), "NestField"; got != want { - t.Errorf("c1.RHS() = %q; want %q", got, want) + if got, want := c1.AssignableExpr(), "NestField"; got != want { + t.Errorf("c1.AssignableExpr() = %q; want %q", got, want) } c2 := FieldPathComponent{ Name: "nest2_field", Target: nest.Fields[0], } - if got, want := c2.LHS(), "Nest2Field"; got != want { - t.Errorf("c2.LHS() = %q; want %q", got, want) + if got, want := c2.ValueExpr(), "Nest2Field"; got != want { + t.Errorf("c2.ValueExpr() = %q; want %q", got, want) } - if got, want := c2.LHS(), "Nest2Field"; got != want { - t.Errorf("c2.LHS() = %q; want %q", got, want) + if got, want := c2.ValueExpr(), "Nest2Field"; got != want { + t.Errorf("c2.ValueExpr() = %q; want %q", got, want) } fp := FieldPath{ @@ -185,8 +185,8 @@ func TestFieldPath(t *testing.T) { Target: nest.Fields[1], }, } - if got, want := fp.RHS("resp"), "resp.GetNestField().Nest2Field.GetNestField().TerminalField"; got != want { - t.Errorf("fp.RHS(%q) = %q; want %q", "resp", got, want) + if got, want := fp.AssignableExpr("resp"), "resp.GetNestField().Nest2Field.GetNestField().TerminalField"; got != want { + t.Errorf("fp.AssignableExpr(%q) = %q; want %q", "resp", got, want) } fp2 := FieldPath{ @@ -195,12 +195,12 @@ func TestFieldPath(t *testing.T) { Target: nest2.Fields[1], }, } - if got, want := fp2.RHS("resp"), "resp.Nest2Field.GetNestField().Nest2Field.TerminalField"; got != want { - t.Errorf("fp2.RHS(%q) = %q; want %q", "resp", got, want) + if got, want := fp2.AssignableExpr("resp"), "resp.Nest2Field.GetNestField().Nest2Field.TerminalField"; got != want { + t.Errorf("fp2.AssignableExpr(%q) = %q; want %q", "resp", got, want) } var fpEmpty FieldPath - if got, want := fpEmpty.RHS("resp"), "resp"; got != want { - t.Errorf("fpEmpty.RHS(%q) = %q; want %q", "resp", got, want) + if got, want := fpEmpty.AssignableExpr("resp"), "resp"; got != want { + t.Errorf("fpEmpty.AssignableExpr(%q) = %q; want %q", "resp", got, want) } } diff --git a/protoc-gen-grpc-gateway/gengateway/template.go b/protoc-gen-grpc-gateway/gengateway/template.go index ef52049a625..b862e00fc3d 100644 --- a/protoc-gen-grpc-gateway/gengateway/template.go +++ b/protoc-gen-grpc-gateway/gengateway/template.go @@ -208,7 +208,7 @@ var ( var metadata runtime.ServerMetadata {{if .Body}} if req.ContentLength > 0 { - if err := marshaler.NewDecoder(req.Body).Decode(&{{.Body.RHS "protoReq"}}); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&{{.Body.AssignableExpr "protoReq"}}); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } } @@ -228,7 +228,7 @@ var ( {{if $param.IsNestedProto3 }} err = runtime.PopulateFieldFromPath(&protoReq, {{$param | printf "%q"}}, val) {{else}} - {{$param.RHS "protoReq"}}, err = {{$param.ConvertFuncExpr}}(val) + {{$param.AssignableExpr "protoReq"}}, err = {{$param.ConvertFuncExpr}}(val) {{end}} if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", {{$param | printf "%q"}}, err)