fix golint issues, else blocks (#457)
This commit is contained in:
@@ -35,9 +35,9 @@ func (o *fieldOptionsWithContext) fromString() bool {
|
||||
func (o *fieldOptionsWithContext) getDefault() (string, bool) {
|
||||
if o == nil {
|
||||
return "", false
|
||||
} else {
|
||||
return o.Default, len(o.Default) > 0
|
||||
}
|
||||
|
||||
return o.Default, len(o.Default) > 0
|
||||
}
|
||||
|
||||
func (o *fieldOptionsWithContext) optional() bool {
|
||||
@@ -55,9 +55,9 @@ func (o *fieldOptionsWithContext) options() []string {
|
||||
func (o *fieldOptions) optionalDep() string {
|
||||
if o == nil {
|
||||
return ""
|
||||
} else {
|
||||
return o.OptionalDep
|
||||
}
|
||||
|
||||
return o.OptionalDep
|
||||
}
|
||||
|
||||
func (o *fieldOptions) toOptionsWithContext(key string, m Valuer, fullName string) (
|
||||
@@ -77,29 +77,29 @@ func (o *fieldOptions) toOptionsWithContext(key string, m Valuer, fullName strin
|
||||
_, selfOn := m.Value(key)
|
||||
if baseOn == selfOn {
|
||||
return nil, fmt.Errorf("set value for either %q or %q in %q", dep, key, fullName)
|
||||
} else {
|
||||
optional = baseOn
|
||||
}
|
||||
|
||||
optional = baseOn
|
||||
} else {
|
||||
_, baseOn := m.Value(dep)
|
||||
_, selfOn := m.Value(key)
|
||||
if baseOn != selfOn {
|
||||
return nil, fmt.Errorf("values for %q and %q should be both provided or both not in %q",
|
||||
dep, key, fullName)
|
||||
} else {
|
||||
optional = !baseOn
|
||||
}
|
||||
|
||||
optional = !baseOn
|
||||
}
|
||||
}
|
||||
|
||||
if o.fieldOptionsWithContext.Optional == optional {
|
||||
return &o.fieldOptionsWithContext, nil
|
||||
} else {
|
||||
return &fieldOptionsWithContext{
|
||||
FromString: o.FromString,
|
||||
Optional: optional,
|
||||
Options: o.Options,
|
||||
Default: o.Default,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &fieldOptionsWithContext{
|
||||
FromString: o.FromString,
|
||||
Optional: optional,
|
||||
Options: o.Options,
|
||||
Default: o.Default,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -114,9 +114,9 @@ func (u *Unmarshaler) processAnonymousField(field reflect.StructField, value ref
|
||||
|
||||
if options.optional() {
|
||||
return u.processAnonymousFieldOptional(field, value, key, m, fullName)
|
||||
} else {
|
||||
return u.processAnonymousFieldRequired(field, value, m, fullName)
|
||||
}
|
||||
|
||||
return u.processAnonymousFieldRequired(field, value, m, fullName)
|
||||
}
|
||||
|
||||
func (u *Unmarshaler) processAnonymousFieldOptional(field reflect.StructField, value reflect.Value,
|
||||
@@ -184,9 +184,9 @@ func (u *Unmarshaler) processField(field reflect.StructField, value reflect.Valu
|
||||
|
||||
if field.Anonymous {
|
||||
return u.processAnonymousField(field, value, m, fullName)
|
||||
} else {
|
||||
return u.processNamedField(field, value, m, fullName)
|
||||
}
|
||||
|
||||
return u.processNamedField(field, value, m, fullName)
|
||||
}
|
||||
|
||||
func (u *Unmarshaler) processFieldNotFromString(field reflect.StructField, value reflect.Value,
|
||||
@@ -319,9 +319,9 @@ func (u *Unmarshaler) processNamedField(field reflect.StructField, value reflect
|
||||
mapValue, hasValue := getValue(m, key)
|
||||
if hasValue {
|
||||
return u.processNamedFieldWithValue(field, value, mapValue, key, opts, fullName)
|
||||
} else {
|
||||
return u.processNamedFieldWithoutValue(field, value, opts, fullName)
|
||||
}
|
||||
|
||||
return u.processNamedFieldWithoutValue(field, value, opts, fullName)
|
||||
}
|
||||
|
||||
func (u *Unmarshaler) processNamedFieldWithValue(field reflect.StructField, value reflect.Value,
|
||||
@@ -329,9 +329,9 @@ func (u *Unmarshaler) processNamedFieldWithValue(field reflect.StructField, valu
|
||||
if mapValue == nil {
|
||||
if opts.optional() {
|
||||
return nil
|
||||
} else {
|
||||
return fmt.Errorf("field %s mustn't be nil", key)
|
||||
}
|
||||
|
||||
return fmt.Errorf("field %s mustn't be nil", key)
|
||||
}
|
||||
|
||||
maybeNewValue(field, value)
|
||||
|
||||
@@ -124,23 +124,26 @@ func convertType(kind reflect.Kind, str string) (interface{}, error) {
|
||||
case reflect.Bool:
|
||||
return str == "1" || strings.ToLower(str) == "true", nil
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
if intValue, err := strconv.ParseInt(str, 10, 64); err != nil {
|
||||
intValue, err := strconv.ParseInt(str, 10, 64)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("the value %q cannot parsed as int", str)
|
||||
} else {
|
||||
return intValue, nil
|
||||
}
|
||||
|
||||
return intValue, nil
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
if uintValue, err := strconv.ParseUint(str, 10, 64); err != nil {
|
||||
uintValue, err := strconv.ParseUint(str, 10, 64)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("the value %q cannot parsed as uint", str)
|
||||
} else {
|
||||
return uintValue, nil
|
||||
}
|
||||
|
||||
return uintValue, nil
|
||||
case reflect.Float32, reflect.Float64:
|
||||
if floatValue, err := strconv.ParseFloat(str, 64); err != nil {
|
||||
floatValue, err := strconv.ParseFloat(str, 64)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("the value %q cannot parsed as float", str)
|
||||
} else {
|
||||
return floatValue, nil
|
||||
}
|
||||
|
||||
return floatValue, nil
|
||||
case reflect.String:
|
||||
return str, nil
|
||||
default:
|
||||
@@ -180,26 +183,28 @@ func doParseKeyAndOptions(field reflect.StructField, value string) (string, *fie
|
||||
segs := strings.Split(option, equalToken)
|
||||
if len(segs) != 2 {
|
||||
return "", nil, fmt.Errorf("field %s has wrong options", field.Name)
|
||||
} else {
|
||||
fieldOpts.Options = strings.Split(segs[1], optionSeparator)
|
||||
}
|
||||
|
||||
fieldOpts.Options = strings.Split(segs[1], optionSeparator)
|
||||
case strings.HasPrefix(option, defaultOption):
|
||||
segs := strings.Split(option, equalToken)
|
||||
if len(segs) != 2 {
|
||||
return "", nil, fmt.Errorf("field %s has wrong default option", field.Name)
|
||||
} else {
|
||||
fieldOpts.Default = strings.TrimSpace(segs[1])
|
||||
}
|
||||
|
||||
fieldOpts.Default = strings.TrimSpace(segs[1])
|
||||
case strings.HasPrefix(option, rangeOption):
|
||||
segs := strings.Split(option, equalToken)
|
||||
if len(segs) != 2 {
|
||||
return "", nil, fmt.Errorf("field %s has wrong range", field.Name)
|
||||
}
|
||||
if nr, err := parseNumberRange(segs[1]); err != nil {
|
||||
|
||||
nr, err := parseNumberRange(segs[1])
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
} else {
|
||||
fieldOpts.Range = nr
|
||||
}
|
||||
|
||||
fieldOpts.Range = nr
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ func unmarshalYamlBytes(content []byte, v interface{}, unmarshaler *Unmarshaler)
|
||||
|
||||
if m, ok := o.(map[string]interface{}); ok {
|
||||
return unmarshaler.Unmarshal(m, v)
|
||||
} else {
|
||||
return ErrUnsupportedType
|
||||
}
|
||||
|
||||
return ErrUnsupportedType
|
||||
}
|
||||
|
||||
func unmarshalYamlReader(reader io.Reader, v interface{}, unmarshaler *Unmarshaler) error {
|
||||
|
||||
Reference in New Issue
Block a user