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

Function parseReqParam

protoc-gen-openapiv2/main.go:274–318  ·  view source on GitHub ↗

parseReqParam parses a CodeGeneratorRequest parameter and adds the extracted values to the given FlagSet and pkgMap. Returns a non-nil error if setting a flag failed.

(param string, f *flag.FlagSet, pkgMap map[string]string)

Source from the content-addressed store, hash-verified

272// extracted values to the given FlagSet and pkgMap. Returns a non-nil
273// error if setting a flag failed.
274func parseReqParam(param string, f *flag.FlagSet, pkgMap map[string]string) error {
275 if param == "" {
276 return nil
277 }
278 for _, p := range strings.Split(param, ",") {
279 spec := strings.SplitN(p, "=", 2)
280 if len(spec) == 1 {
281 switch spec[0] {
282 case "allow_delete_body":
283 if err := f.Set(spec[0], "true"); err != nil {
284 return fmt.Errorf("cannot set flag %s: %w", p, err)
285 }
286 continue
287 case "allow_merge":
288 if err := f.Set(spec[0], "true"); err != nil {
289 return fmt.Errorf("cannot set flag %s: %w", p, err)
290 }
291 continue
292 case "allow_repeated_fields_in_body":
293 if err := f.Set(spec[0], "true"); err != nil {
294 return fmt.Errorf("cannot set flag %s: %w", p, err)
295 }
296 continue
297 case "include_package_in_tags":
298 if err := f.Set(spec[0], "true"); err != nil {
299 return fmt.Errorf("cannot set flag %s: %w", p, err)
300 }
301 continue
302 }
303 if err := f.Set(spec[0], ""); err != nil {
304 return fmt.Errorf("cannot set flag %s: %w", p, err)
305 }
306 continue
307 }
308 name, value := spec[0], spec[1]
309 if strings.HasPrefix(name, "M") {
310 pkgMap[name[1:]] = value
311 continue
312 }
313 if err := f.Set(name, value); err != nil {
314 return fmt.Errorf("cannot set flag %s: %w", p, err)
315 }
316 }
317 return nil
318}

Callers 2

TestParseReqParamFunction · 0.85
mainFunction · 0.85

Calls 1

SetMethod · 0.80

Tested by 1

TestParseReqParamFunction · 0.68