yamlFieldNames returns the set of YAML tag names for the given struct type.
(v interface{})
| 21 | |
| 22 | // yamlFieldNames returns the set of YAML tag names for the given struct type. |
| 23 | func yamlFieldNames(v interface{}) map[string]bool { |
| 24 | t := reflect.TypeOf(v) |
| 25 | fields := make(map[string]bool, t.NumField()) |
| 26 | for i := range t.NumField() { |
| 27 | tag := t.Field(i).Tag.Get("yaml") |
| 28 | if tag == "-" { |
| 29 | continue |
| 30 | } |
| 31 | name, _, _ := strings.Cut(tag, ",") |
| 32 | if name != "" { |
| 33 | fields[name] = true |
| 34 | } |
| 35 | } |
| 36 | return fields |
| 37 | } |
| 38 | |
| 39 | // asMap asserts that v is a map[string]interface{}, returning false if not. |
| 40 | // Callers should warn when this fails on user input, as it signals malformed YAML. |
no test coverage detected