MCPcopy
hub / github.com/pquerna/ffjson / dominantField

Function dominantField

inception/reflect.go:268–290  ·  view source on GitHub ↗

dominantField looks through the fields, all of which are known to have the same name, to find the single field that dominates the others using Go's embedding rules, modified by the presence of JSON tags. If there are multiple top-level fields, the boolean will be false: This condition is an error in

(fields []*StructField)

Source from the content-addressed store, hash-verified

266// will be false: This condition is an error in Go and we skip all
267// the fields.
268func dominantField(fields []*StructField) (*StructField, bool) {
269 tagged := -1 // Index of first tagged field.
270 for i, f := range fields {
271 if f.Tagged {
272 if tagged >= 0 {
273 // Multiple tagged fields at the same level: conflict.
274 // Return no field.
275 return nil, false
276 }
277 tagged = i
278 }
279 }
280 if tagged >= 0 {
281 return fields[tagged], true
282 }
283 // All remaining fields have the same length. If there's more than one,
284 // we have a conflict (two fields named "X" at the same level) and we
285 // return no field.
286 if len(fields) > 1 {
287 return nil, false
288 }
289 return fields[0], true
290}

Callers 1

extractFieldsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…