Skip to content

Commit b8953b2

Browse files
author
Breno Loyola
committed
instead of parsing queryParams all the time just parse them once
1 parent 0d7fc4e commit b8953b2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

unmarshal.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package queryparam
22

33
import (
4-
"reflect"
54
"errors"
6-
"net/url"
75
"fmt"
6+
"net/url"
7+
"reflect"
88
"strings"
99
)
1010

@@ -28,7 +28,7 @@ func delimiterFromField(field reflect.StructField) string {
2828
return defaultDelimiter
2929
}
3030

31-
func unmarshalField(v reflect.Value, t reflect.Type, i int, u *url.URL) error {
31+
func unmarshalField(v reflect.Value, t reflect.Type, i int, qs url.Values) error {
3232
var (
3333
field reflect.StructField
3434
paramVal string
@@ -42,7 +42,7 @@ func unmarshalField(v reflect.Value, t reflect.Type, i int, u *url.URL) error {
4242
return nil
4343
}
4444

45-
paramVal = u.Query().Get(tagVal)
45+
paramVal = qs.Get(tagVal)
4646
if len(paramVal) == 0 {
4747
return nil
4848
}
@@ -75,8 +75,9 @@ func Unmarshal(u *url.URL, i interface{}) error {
7575
v := iVal.Elem()
7676
t := v.Type()
7777

78+
qs := u.Query()
7879
for i := 0; i < t.NumField(); i++ {
79-
if err := unmarshalField(v, t, i, u); err != nil {
80+
if err := unmarshalField(v, t, i, qs); err != nil {
8081
return err
8182
}
8283
}

0 commit comments

Comments
 (0)