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

Function marshalMap

cli/command/formatter/reflect.go:25–49  ·  view source on GitHub ↗

marshalMap marshals x to map[string]any

(x any)

Source from the content-addressed store, hash-verified

23
24// marshalMap marshals x to map[string]any
25func marshalMap(x any) (map[string]any, error) {
26 val := reflect.ValueOf(x)
27 if val.Kind() != reflect.Pointer {
28 return nil, fmt.Errorf("expected a pointer to a struct, got %v", val.Kind())
29 }
30 if val.IsNil() {
31 return nil, errors.New("expected a pointer to a struct, got nil pointer")
32 }
33 valElem := val.Elem()
34 if valElem.Kind() != reflect.Struct {
35 return nil, fmt.Errorf("expected a pointer to a struct, got a pointer to %v", valElem.Kind())
36 }
37 typ := val.Type()
38 m := make(map[string]any)
39 for i := 0; i < val.NumMethod(); i++ {
40 k, v, err := marshalForMethod(typ.Method(i), val.Method(i))
41 if err != nil {
42 return nil, err
43 }
44 if k != "" {
45 m[k] = v
46 }
47 }
48 return m, nil
49}
50
51var unmarshallableNames = map[string]struct{}{"FullHeader": {}}
52

Callers 3

TestMarshalMapFunction · 0.85
TestMarshalMapBadFunction · 0.85
MarshalJSONFunction · 0.85

Calls 2

marshalForMethodFunction · 0.85
TypeMethod · 0.45

Tested by 2

TestMarshalMapFunction · 0.68
TestMarshalMapBadFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…