MCPcopy
hub / github.com/openai/openai-go / typeDecoder

Method typeDecoder

internal/apijson/decoder.go:109–142  ·  view source on GitHub ↗
(t reflect.Type)

Source from the content-addressed store, hash-verified

107}
108
109func (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.

Callers 9

unmarshalMethod · 0.95
validatedTypeDecoderMethod · 0.95
newTypeDecoderMethod · 0.95
newMapDecoderMethod · 0.95
newArrayTypeDecoderMethod · 0.95
newStructTypeDecoderMethod · 0.95
newStructUnionDecoderMethod · 0.95
newUnionDecoderMethod · 0.95

Calls 2

newTypeDecoderMethod · 0.95
decoderFuncFuncType · 0.85

Tested by

no test coverage detected