(svc *Service, md *descriptorpb.MethodDescriptorProto, optsList []*options.HttpRule)
| 80 | } |
| 81 | |
| 82 | func (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 |
no test coverage detected