Map returns the Struct proto as a map[string]interface{}.
(p *structpb.Struct, opts ...Option)
| 58 | |
| 59 | // Map returns the Struct proto as a map[string]interface{}. |
| 60 | func Map(p *structpb.Struct, opts ...Option) (map[string]any, error) { |
| 61 | if p == nil || len(p.Fields) == 0 { |
| 62 | return nil, nil |
| 63 | } |
| 64 | state, err := createSerializationState(opts...) |
| 65 | if err != nil { |
| 66 | return nil, err |
| 67 | } |
| 68 | m := make(map[string]any, len(p.Fields)) |
| 69 | for k, v := range p.Fields { |
| 70 | if v == nil { |
| 71 | continue |
| 72 | } |
| 73 | gv, err := Interface(v, state.Recurse()) |
| 74 | if err != nil { |
| 75 | return nil, err |
| 76 | } |
| 77 | m[k] = gv |
| 78 | } |
| 79 | return m, nil |
| 80 | } |
| 81 | |
| 82 | // Slice returns the ListValue proto as a []interface{}. |
| 83 | func Slice(l *structpb.ListValue, opts ...Option) ([]any, error) { |