Skip to content

Commit

Permalink
Merge pull request #13 from go-carrot/br.lint
Browse files Browse the repository at this point in the history
Satisfy linter
  • Loading branch information
BrandonRomano authored Jun 23, 2017
2 parents 255013d + e9f5736 commit c75e1c1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 5 additions & 0 deletions null_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"
)

// NullIntHandler is a TypeHandler for null.Int
func NullIntHandler(input string, value *Value) error {
// Get int64
res, err := strconv.ParseInt(input, 10, 64)
Expand All @@ -21,13 +22,15 @@ func NullIntHandler(input string, value *Value) error {
return nil
}

// NullStringHandler is a TypeHandler for null.String
func NullStringHandler(input string, value *Value) error {
nullString := value.Result.(*null.String)
(*nullString).String = input
(*nullString).Valid = true
return nil
}

// NullFloatHandler is a TypeHandler for null.Float
func NullFloatHandler(input string, value *Value) error {
// Get float64
res, err := strconv.ParseFloat(input, 64)
Expand All @@ -42,6 +45,7 @@ func NullFloatHandler(input string, value *Value) error {
return nil
}

// NullBoolHandler is a TypeHandler for null.Bool
func NullBoolHandler(input string, value *Value) error {
// Get bool
res, err := strconv.ParseBool(input)
Expand All @@ -56,6 +60,7 @@ func NullBoolHandler(input string, value *Value) error {
return nil
}

// NullTimeHandler is a TypeHandler for null.Time
func NullTimeHandler(input string, value *Value) error {
// Get time.Time
res, err := time.Parse(time.RFC3339, input)
Expand Down
3 changes: 1 addition & 2 deletions validator.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package validator

import (
"errors"
"fmt"
"reflect"
"time"
Expand Down Expand Up @@ -68,7 +67,7 @@ func Validate(values []*Value) error {
func applyTypeHandler(value *Value) error {
switch i := (value.Result).(type) {
default:
return errors.New(fmt.Sprintf("go-carrot/validator cannot by default handle a Value with Result of type %v. Must set a custom TypeHandler for %v.", reflect.TypeOf(i), value.Name))
return fmt.Errorf("go-carrot/validator cannot by default handle a Value with Result of type %v. Must set a custom TypeHandler for %v.", reflect.TypeOf(i), value.Name)
case *string:
value.TypeHandler = stringHandler
case *float32:
Expand Down

0 comments on commit c75e1c1

Please sign in to comment.