From e0fac283eb1a96bdb68d70c234f4eb9080752846 Mon Sep 17 00:00:00 2001 From: 14March <53811984+hcraM41@users.noreply.github.com> Date: Thu, 24 Apr 2025 10:07:53 +0800 Subject: [PATCH] code opt: prioritize handling boundary conditions --- query/encode.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/query/encode.go b/query/encode.go index f877b1c..6359da8 100644 --- a/query/encode.go +++ b/query/encode.go @@ -125,6 +125,11 @@ type Encoder interface { // as multiple URL values of the same name. func Values(v interface{}) (url.Values, error) { values := make(url.Values) + + if v == nil { + return values, nil + } + val := reflect.ValueOf(v) for val.Kind() == reflect.Ptr { if val.IsNil() { @@ -133,10 +138,6 @@ func Values(v interface{}) (url.Values, error) { val = val.Elem() } - if v == nil { - return values, nil - } - if val.Kind() != reflect.Struct { return nil, fmt.Errorf("query: Values() expects struct input. Got %v", val.Kind()) }