MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / newMethod

Method newMethod

internal/descriptor/services.go:82–212  ·  view source on GitHub ↗
(svc *Service, md *descriptorpb.MethodDescriptorProto, optsList []*options.HttpRule)

Source from the content-addressed store, hash-verified

80}
81
82func (r *Registry) newMethod(svc *Service, md *descriptorpb.MethodDescriptorProto, optsList []*options.HttpRule) (*Method, error) {
83 requestType, err := r.LookupMsg(svc.File.GetPackage(), md.GetInputType())
84 if err != nil {
85 return nil, err
86 }
87 responseType, err := r.LookupMsg(svc.File.GetPackage(), md.GetOutputType())
88 if err != nil {
89 return nil, err
90 }
91 meth := &Method{
92 Service: svc,
93 MethodDescriptorProto: md,
94 RequestType: requestType,
95 ResponseType: responseType,
96 }
97
98 newBinding := func(opts *options.HttpRule, idx int) (*Binding, error) {
99 var (
100 httpMethod string
101 pathTemplate string
102 )
103 switch {
104 case opts.GetGet() != "":
105 httpMethod = "GET"
106 pathTemplate = opts.GetGet()
107 if opts.Body != "" {
108 return nil, fmt.Errorf("must not set request body when http method is GET: %s", md.GetName())
109 }
110
111 case opts.GetPut() != "":
112 httpMethod = "PUT"
113 pathTemplate = opts.GetPut()
114
115 case opts.GetPost() != "":
116 httpMethod = "POST"
117 pathTemplate = opts.GetPost()
118
119 case opts.GetDelete() != "":
120 httpMethod = "DELETE"
121 pathTemplate = opts.GetDelete()
122 if opts.Body != "" && !r.allowDeleteBody {
123 return nil, fmt.Errorf("must not set request body when http method is DELETE except allow_delete_body option is true: %s", md.GetName())
124 }
125
126 case opts.GetPatch() != "":
127 httpMethod = "PATCH"
128 pathTemplate = opts.GetPatch()
129
130 case opts.GetCustom() != nil:
131 custom := opts.GetCustom()
132 httpMethod = custom.Kind
133 pathTemplate = custom.Path
134
135 default:
136 if grpclog.V(1) {
137 grpclog.Infof("No pattern specified in google.api.HttpRule: %s", md.GetName())
138 }
139 return nil, nil

Callers 1

loadServicesMethod · 0.95

Calls 7

LookupMsgMethod · 0.95
newParamMethod · 0.95
newBodyMethod · 0.95
newResponseMethod · 0.95
ParseFunction · 0.92
CompileMethod · 0.65
GetNameMethod · 0.45

Tested by

no test coverage detected