diff --git a/query/encode.go b/query/encode.go index f877b1c..51046ab 100644 --- a/query/encode.go +++ b/query/encode.go @@ -256,7 +256,7 @@ func reflectValue(values url.Values, val reflect.Value, scope string) error { continue } - if sv.Kind() == reflect.Struct { + if sv.Kind() == reflect.Struct && !opts.Contains("string") { if err := reflectValue(values, sv, name); err != nil { return err } diff --git a/query/encode_test.go b/query/encode_test.go index a94b44d..10af29d 100644 --- a/query/encode_test.go +++ b/query/encode_test.go @@ -745,3 +745,35 @@ func TestParseTag(t *testing.T) { } } } + +type customStructString struct { + v string +} + +func (s customStructString) String() string { + return s.v +} + +func TestValues_CustomStructStringValue(t *testing.T) { + tests := []struct { + input interface{} + want url.Values + }{ + { + struct { + V customStructString `url:"v,string"` + }{customStructString{"a"}}, + url.Values{"v": {"a"}}, + }, + { + struct { + V customStructString `url:"v"` + }{}, + url.Values{}, + }, + } + + for _, tt := range tests { + testValue(t, tt.input, tt.want) + } +}