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)
| 266 | // will be false: This condition is an error in Go and we skip all |
| 267 | // the fields. |
| 268 | func 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 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…