CheckRequiredFields checks that all fields that are tagged as required in cfg's type have actually been set to a value other than the field type zero value. If not CheckRequiredFields returns the name of the first required field that is not set, or, it returns an empty string if all required fields
(cfg interface{})
| 553 | // |
| 554 | // CheckRequiredFields doesn't support struct embedding other structs. |
| 555 | func CheckRequiredFields(cfg interface{}) string { |
| 556 | fields := RequiredFields(cfg) |
| 557 | |
| 558 | for _, name := range fields { |
| 559 | rv := reflect.ValueOf(cfg).Elem() |
| 560 | fv := rv.FieldByName(name) |
| 561 | if fv.IsZero() { |
| 562 | return name |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | return "" |
| 567 | } |
| 568 | |
| 569 | // ErrorRequiredField describes the absence of a required field |
| 570 | // in a component configuration. |