// CheckRequiredFieldsInStruct checks if the given struct's required field(s) are set or not.
//nolint:nestif,gocritic
CheckRequiredFieldsInStruct checks if the given struct's required field(s) are set or not.
nolint:nestif,gocritic
// CheckRequiredFieldsInStruct checks if the given struct ' s required field ( s ) are set or not . // nolint : nestif gocritic
func CheckRequiredFieldsInStruct(s CustomStruct) []error {
	errs := make([]error, 0)
	v := reflect.ValueOf(s.Struct)
	if v.Kind() == reflect.Struct {
		vt := v.Type() 
		for i := 0; i < v.NumField(); i++ {
			if vt.Field(i).PkgPath != "" {
				continue 
			}
			if vt.Field(i).Tag.Get("required") == "false" || vt.Field(i).Tag.Get("required") == "" {
				continue 
			}
			if v.Field(i).IsZero() {
				var err error
				if vt.Field(i).Tag.Get("chain") != "" {
					if s.IsListItem {
						msg := strings.Replace(vt.Field(i).Tag.Get("chain"), ".N.", "."+strconv.Itoa(s.Index)+".", 1)
						err = fmt.Errorf(msg)
					} else {
						err = fmt.Errorf(vt.Field(i).Tag.Get("chain"))
					}
				} else if vt.Field(i).Tag.Get("mapstructure") != "" {
					err = fmt.Errorf(vt.Field(i).Tag.Get("mapstructure"))
				} else {
					err = fmt.Errorf(vt.Field(i).Tag.Get("yaml"))
				}
				if err != nil {
					errs = append(errs, err)
				}
			}
		}
	}
	return errs
}
func CheckRequiredFieldsInStruct ( s CustomStruct ) [ ] error { errs := make ( [ ] error , 0 ) v := reflect . ValueOf ( s . Struct ) if v . Kind ( ) == reflect . Struct { vt := v . Type ( ) for i := 0 ; i < v . NumField ( ) ; i ++ { if vt . Field ( i ) . PkgPath != " " { continue } if vt . Field ( i ) . Tag . Get ( " " ) == " " || vt . Field ( i ) . Tag . Get ( " " ) == " " { continue } if v . Field ( i ) . IsZero ( ) { var err error if vt . Field ( i ) . Tag . Get ( " " ) != " " { if s . IsListItem { msg := strings . Replace ( vt . Field ( i ) . Tag . Get ( " " ) , " " , " " + strconv . Itoa ( s . Index ) + " " , 1 ) err = fmt . Errorf ( msg ) } else { err = fmt . Errorf ( vt . Field ( i ) . Tag . Get ( " " ) ) } } else if vt . Field ( i ) . Tag . Get ( " " ) != " " { err = fmt . Errorf ( vt . Field ( i ) . Tag . Get ( " " ) ) } else { err = fmt . Errorf ( vt . Field ( i ) . Tag . Get ( " " ) ) } if err != nil { errs = append ( errs , err ) } } } } return errs }
CheckRequiredFieldsInStruct checks if the given struct's required field(s) are set or not.
CheckRequiredFieldsInStruct checks if the given struct ' s required field ( s ) are set or not .
// to get the filed info like tags, pkgpath etc // Private field // check if the required tag is true // optional field