Skip to content

Commit ffb7deb

Browse files
hcraM41willnorris
authored andcommitted
code opt: prioritize handling boundary conditions
1 parent 085cc78 commit ffb7deb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

query/encode.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ type Encoder interface {
125125
// as multiple URL values of the same name.
126126
func Values(v interface{}) (url.Values, error) {
127127
values := make(url.Values)
128+
129+
if v == nil {
130+
return values, nil
131+
}
132+
128133
val := reflect.ValueOf(v)
129134
for val.Kind() == reflect.Ptr {
130135
if val.IsNil() {
@@ -133,10 +138,6 @@ func Values(v interface{}) (url.Values, error) {
133138
val = val.Elem()
134139
}
135140

136-
if v == nil {
137-
return values, nil
138-
}
139-
140141
if val.Kind() != reflect.Struct {
141142
return nil, fmt.Errorf("query: Values() expects struct input. Got %v", val.Kind())
142143
}

0 commit comments

Comments
 (0)