fix gocyclo warnings (#278)

master
Kevin Wan 4 years ago committed by GitHub
parent c686c93fb5
commit c435811479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -153,58 +153,57 @@ func doParseKeyAndOptions(field reflect.StructField, value string) (string, *fie
key := strings.TrimSpace(segments[0]) key := strings.TrimSpace(segments[0])
options := segments[1:] options := segments[1:]
if len(options) > 0 { if len(options) == 0 {
var fieldOpts fieldOptions return key, nil, nil
}
for _, segment := range options {
option := strings.TrimSpace(segment) var fieldOpts fieldOptions
switch { for _, segment := range options {
case option == stringOption: option := strings.TrimSpace(segment)
fieldOpts.FromString = true switch {
case strings.HasPrefix(option, optionalOption): case option == stringOption:
segs := strings.Split(option, equalToken) fieldOpts.FromString = true
switch len(segs) { case strings.HasPrefix(option, optionalOption):
case 1: segs := strings.Split(option, equalToken)
fieldOpts.Optional = true switch len(segs) {
case 2: case 1:
fieldOpts.Optional = true fieldOpts.Optional = true
fieldOpts.OptionalDep = segs[1] case 2:
default:
return "", nil, fmt.Errorf("field %s has wrong optional", field.Name)
}
case option == optionalOption:
fieldOpts.Optional = true fieldOpts.Optional = true
case strings.HasPrefix(option, optionsOption): fieldOpts.OptionalDep = segs[1]
segs := strings.Split(option, equalToken) default:
if len(segs) != 2 { return "", nil, fmt.Errorf("field %s has wrong optional", field.Name)
return "", nil, fmt.Errorf("field %s has wrong options", field.Name) }
} else { case option == optionalOption:
fieldOpts.Options = strings.Split(segs[1], optionSeparator) fieldOpts.Optional = true
} case strings.HasPrefix(option, optionsOption):
case strings.HasPrefix(option, defaultOption): segs := strings.Split(option, equalToken)
segs := strings.Split(option, equalToken) if len(segs) != 2 {
if len(segs) != 2 { return "", nil, fmt.Errorf("field %s has wrong options", field.Name)
return "", nil, fmt.Errorf("field %s has wrong default option", field.Name) } else {
} else { fieldOpts.Options = strings.Split(segs[1], optionSeparator)
fieldOpts.Default = strings.TrimSpace(segs[1]) }
} case strings.HasPrefix(option, defaultOption):
case strings.HasPrefix(option, rangeOption): segs := strings.Split(option, equalToken)
segs := strings.Split(option, equalToken) if len(segs) != 2 {
if len(segs) != 2 { return "", nil, fmt.Errorf("field %s has wrong default option", field.Name)
return "", nil, fmt.Errorf("field %s has wrong range", field.Name) } else {
} fieldOpts.Default = strings.TrimSpace(segs[1])
if nr, err := parseNumberRange(segs[1]); err != nil { }
return "", nil, err case strings.HasPrefix(option, rangeOption):
} else { segs := strings.Split(option, equalToken)
fieldOpts.Range = nr if len(segs) != 2 {
} return "", nil, fmt.Errorf("field %s has wrong range", field.Name)
}
if nr, err := parseNumberRange(segs[1]); err != nil {
return "", nil, err
} else {
fieldOpts.Range = nr
} }
} }
return key, &fieldOpts, nil
} }
return key, nil, nil return key, &fieldOpts, nil
} }
func implicitValueRequiredStruct(tag string, tp reflect.Type) (bool, error) { func implicitValueRequiredStruct(tag string, tp reflect.Type) (bool, error) {

Loading…
Cancel
Save