MCPcopy Create free account
hub / github.com/AdRoll/baker / RequiredFields

Function RequiredFields

config.go:530–546  ·  view source on GitHub ↗

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{})

Source from the content-addressed store, hash-verified

528//
529// RequiredFields doesn't support struct embedding other structs.
530func 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

Callers 2

TestRequiredFieldsFunction · 0.92
CheckRequiredFieldsFunction · 0.85

Calls 1

GetMethod · 0.65

Tested by 1

TestRequiredFieldsFunction · 0.74