Skip to content

Commit

Permalink
argString: refactor out else statement
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsam committed Jun 26, 2018
1 parent 4186810 commit a8a0855
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions gorp.go
Expand Up @@ -127,20 +127,26 @@ type DynamicTable interface {
// interface.
var _, _ SqlExecutor = &DbMap{}, &Transaction{}

func argValue(a interface{}) interface{} {
v, ok := a.(driver.Valuer)
if !ok {
return a
}
vV := reflect.ValueOf(v)
if vV.Kind() == reflect.Ptr && vV.IsNil() {
return nil
}
ret, err := v.Value()
if err != nil {
return a
}
return ret
}

func argsString(args ...interface{}) string {
var margs string
for i, a := range args {
var v interface{} = a
if x, ok := v.(driver.Valuer); ok {
if iV := reflect.ValueOf(x); iV.Kind() == reflect.Ptr && iV.IsNil() {
v = nil
} else {
y, err := x.Value()
if err == nil {
v = y
}
}
}
v := argValue(a)
switch v.(type) {
case string:
v = fmt.Sprintf("%q", v)
Expand Down

0 comments on commit a8a0855

Please sign in to comment.