(t reflect.Type)
| 107 | } |
| 108 | |
| 109 | func (d *decoderBuilder) typeDecoder(t reflect.Type) decoderFunc { |
| 110 | entry := decoderEntry{ |
| 111 | typ: t, |
| 112 | dateFormat: d.dateFormat, |
| 113 | root: d.root, |
| 114 | } |
| 115 | |
| 116 | if fi, ok := decoders.Load(entry); ok { |
| 117 | return fi.(decoderFunc) |
| 118 | } |
| 119 | |
| 120 | // To deal with recursive types, populate the map with an |
| 121 | // indirect func before we build it. This type waits on the |
| 122 | // real func (f) to be ready and then calls it. This indirect |
| 123 | // func is only used for recursive types. |
| 124 | var ( |
| 125 | wg sync.WaitGroup |
| 126 | f decoderFunc |
| 127 | ) |
| 128 | wg.Add(1) |
| 129 | fi, loaded := decoders.LoadOrStore(entry, decoderFunc(func(node gjson.Result, v reflect.Value, state *decoderState) error { |
| 130 | wg.Wait() |
| 131 | return f(node, v, state) |
| 132 | })) |
| 133 | if loaded { |
| 134 | return fi.(decoderFunc) |
| 135 | } |
| 136 | |
| 137 | // Compute the real decoder and replace the indirect func with it. |
| 138 | f = d.newTypeDecoder(t) |
| 139 | wg.Done() |
| 140 | decoders.Store(entry, f) |
| 141 | return f |
| 142 | } |
| 143 | |
| 144 | // validatedTypeDecoder wraps the type decoder with a validator. This is helpful |
| 145 | // for ensuring that enum fields are correct. |
no test coverage detected