(st reflect.Type)
| 525 | } |
| 526 | |
| 527 | func getStructInfo(st reflect.Type) (*structInfo, error) { |
| 528 | fieldMapMutex.RLock() |
| 529 | sinfo, found := structMap[st] |
| 530 | fieldMapMutex.RUnlock() |
| 531 | if found { |
| 532 | return sinfo, nil |
| 533 | } |
| 534 | |
| 535 | n := st.NumField() |
| 536 | fieldsMap := make(map[string]fieldInfo) |
| 537 | fieldsList := make([]fieldInfo, 0, n) |
| 538 | inlineMap := -1 |
| 539 | inlineUnmarshalers := [][]int(nil) |
| 540 | for i := 0; i != n; i++ { |
| 541 | field := st.Field(i) |
| 542 | if field.PkgPath != "" && !field.Anonymous { |
| 543 | continue // Private field |
| 544 | } |
| 545 | |
| 546 | info := fieldInfo{Num: i} |
| 547 | |
| 548 | tag := field.Tag.Get("yaml") |
| 549 | if tag == "" && strings.Index(string(field.Tag), ":") < 0 { |
| 550 | tag = string(field.Tag) |
| 551 | } |
| 552 | if tag == "-" { |
| 553 | continue |
| 554 | } |
| 555 | |
| 556 | inline := false |
| 557 | fields := strings.Split(tag, ",") |
| 558 | if len(fields) > 1 { |
| 559 | for _, flag := range fields[1:] { |
| 560 | switch flag { |
| 561 | case "omitempty": |
| 562 | info.OmitEmpty = true |
| 563 | case "flow": |
| 564 | info.Flow = true |
| 565 | case "inline": |
| 566 | inline = true |
| 567 | default: |
| 568 | return nil, errors.New(fmt.Sprintf("unsupported flag %q in tag %q of type %s", flag, tag, st)) |
| 569 | } |
| 570 | } |
| 571 | tag = fields[0] |
| 572 | } |
| 573 | |
| 574 | if inline { |
| 575 | switch field.Type.Kind() { |
| 576 | case reflect.Map: |
| 577 | if inlineMap >= 0 { |
| 578 | return nil, errors.New("multiple ,inline maps in struct " + st.String()) |
| 579 | } |
| 580 | if field.Type.Key() != reflect.TypeOf("") { |
| 581 | return nil, errors.New("option ,inline needs a map with string keys in struct " + st.String()) |
| 582 | } |
| 583 | inlineMap = info.Num |
| 584 | case reflect.Struct, reflect.Ptr: |
no test coverage detected