RequiredFields returns the names of the underlying configuration structure fields which are tagged as required. To tag a field as being required, a "required" struct struct tag must be present and set to true. RequiredFields doesn't support struct embedding other structs.
(cfg interface{})
| 528 | // |
| 529 | // RequiredFields doesn't support struct embedding other structs. |
| 530 | func RequiredFields(cfg interface{}) []string { |
| 531 | var fields []string |
| 532 | |
| 533 | tf := reflect.TypeOf(cfg).Elem() |
| 534 | for i := 0; i < tf.NumField(); i++ { |
| 535 | field := tf.Field(i) |
| 536 | |
| 537 | req := field.Tag.Get("required") |
| 538 | if req != "true" { |
| 539 | continue |
| 540 | } |
| 541 | |
| 542 | fields = append(fields, field.Name) |
| 543 | } |
| 544 | |
| 545 | return fields |
| 546 | } |
| 547 | |
| 548 | // CheckRequiredFields checks that all fields that are tagged as required in |
| 549 | // cfg's type have actually been set to a value other than the field type zero |