Skip to content

Commit

Permalink
Merge pull request #37 from monoculum/fix-linter
Browse files Browse the repository at this point in the history
Fix warnings by linter
  • Loading branch information
emilgpa authored Sep 23, 2020
2 parents bd383fd + b02602f commit 6f187e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
ErrCodeArraySize // Array longer than MaxSize.
)

// Error indicates a error produced
type Error struct {
code uint8
field, path string
Expand All @@ -38,6 +39,7 @@ func (s *Error) Error() string {
return b.String()
}

// MarshalJSON implements the interface Marshaler
func (s Error) MarshalJSON() ([]byte, error) {
return json.Marshal(s.Error())
}
Expand Down
18 changes: 9 additions & 9 deletions formam.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,35 +447,35 @@ func (dec *Decoder) decode() error {
case reflect.String:
dec.curr.SetString(dec.currValues[0])
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
if num, err := strconv.ParseInt(dec.currValues[0], 10, dec.curr.Type().Bits()); err != nil {
num, err := strconv.ParseInt(dec.currValues[0], 10, dec.curr.Type().Bits())
if err != nil {
code := ErrCodeConversion
if err, ok := err.(*strconv.NumError); ok && err.Err == strconv.ErrRange {
code = ErrCodeRange
}
return newError(code, dec.field, dec.path, "could not parse number: %s", err)
} else {
dec.curr.SetInt(num)
}
dec.curr.SetInt(num)
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
if num, err := strconv.ParseUint(dec.currValues[0], 10, dec.curr.Type().Bits()); err != nil {
num, err := strconv.ParseUint(dec.currValues[0], 10, dec.curr.Type().Bits())
if err != nil {
code := ErrCodeConversion
if err, ok := err.(*strconv.NumError); ok && err.Err == strconv.ErrRange {
code = ErrCodeRange
}
return newError(code, dec.field, dec.path, "could not parse number: %s", err)
} else {
dec.curr.SetUint(num)
}
dec.curr.SetUint(num)
case reflect.Float32, reflect.Float64:
if num, err := strconv.ParseFloat(dec.currValues[0], dec.curr.Type().Bits()); err != nil {
num, err := strconv.ParseFloat(dec.currValues[0], dec.curr.Type().Bits())
if err != nil {
code := ErrCodeConversion
if err, ok := err.(*strconv.NumError); ok && err.Err == strconv.ErrRange {
code = ErrCodeRange
}
return newError(code, dec.field, dec.path, "could not parse float: %s", err)
} else {
dec.curr.SetFloat(num)
}
dec.curr.SetFloat(num)
case reflect.Bool:
switch dec.currValues[0] {
case "true", "on", "1", "checked":
Expand Down

0 comments on commit 6f187e4

Please sign in to comment.