marshalMap marshals x to map[string]any
(x any)
| 23 | |
| 24 | // marshalMap marshals x to map[string]any |
| 25 | func 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 | |
| 51 | var unmarshallableNames = map[string]struct{}{"FullHeader": {}} |
| 52 |
searching dependent graphs…