diff --git a/query/encode.go b/query/encode.go index 90dcabb..3d4a01d 100644 --- a/query/encode.go +++ b/query/encode.go @@ -138,7 +138,7 @@ func reflectValue(values url.Values, val reflect.Value, scope string) error { typ := val.Type() for i := 0; i < typ.NumField(); i++ { sf := typ.Field(i) - if sf.PkgPath != "" { // unexported + if sf.PkgPath != "" && !sf.Anonymous { // unexported continue } diff --git a/query/encode_test.go b/query/encode_test.go index e0b2a36..b208da9 100644 --- a/query/encode_test.go +++ b/query/encode_test.go @@ -203,6 +203,15 @@ type D struct { C string } +type e struct { + B + C string +} + +type F struct { + e +} + func TestValues_embeddedStructs(t *testing.T) { tests := []struct { in interface{} @@ -216,6 +225,10 @@ func TestValues_embeddedStructs(t *testing.T) { D{B: B{C: "bar"}, C: "foo"}, url.Values{"C": {"foo", "bar"}}, }, + { + F{e{B: B{C: "bar"}, C: "foo"}}, // With unexported embed + url.Values{"C": {"foo", "bar"}}, + }, } for i, tt := range tests {