MCPcopy Create free account
hub / github.com/docker/cli / marshalForMethod

Function marshalForMethod

cli/command/formatter/reflect.go:55–71  ·  view source on GitHub ↗

marshalForMethod returns the map key and the map value for marshalling the method. It returns ("", nil, nil) for valid but non-marshallable parameter. (e.g. "unexportedFunc()")

(typ reflect.Method, val reflect.Value)

Source from the content-addressed store, hash-verified

53// marshalForMethod returns the map key and the map value for marshalling the method.
54// It returns ("", nil, nil) for valid but non-marshallable parameter. (e.g. "unexportedFunc()")
55func marshalForMethod(typ reflect.Method, val reflect.Value) (string, any, error) {
56 if val.Kind() != reflect.Func {
57 return "", nil, fmt.Errorf("expected func, got %v", val.Kind())
58 }
59 name, numIn, numOut := typ.Name, val.Type().NumIn(), val.Type().NumOut()
60 _, blackListed := unmarshallableNames[name]
61 // FIXME: In text/template, (numOut == 2) is marshallable,
62 // if the type of the second param is error.
63 marshallable := unicode.IsUpper(rune(name[0])) && !blackListed &&
64 numIn == 0 && numOut == 1
65 if !marshallable {
66 return "", nil, nil
67 }
68 result := val.Call(make([]reflect.Value, numIn))
69 intf := result[0].Interface()
70 return name, intf, nil
71}

Callers 1

marshalMapFunction · 0.85

Calls 1

TypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…