Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New array handing options (spotnumbered) #80

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/google/go-querystring
module github.com/nk915/go-querystring

go 1.10

Expand Down
2 changes: 2 additions & 0 deletions query/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ func reflectValue(values url.Values, val reflect.Value, scope string) error {
k := name
if opts.Contains("numbered") {
k = fmt.Sprintf("%s%d", name, i)
} else if opts.Contains("spotnumbered") {
k = fmt.Sprintf("%s.%d", name, i+1)
}
values.Add(k, valueString(sv.Index(i), opts, sf))
}
Expand Down
7 changes: 6 additions & 1 deletion query/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ func TestValues_Slices(t *testing.T) {
}{[2]string{"a", "b"}},
url.Values{"V0": {"a"}, "V1": {"b"}},
},

{
struct {
V [2]string `url:",spotnumbered"`
}{[2]string{"a", "b"}},
url.Values{"V.1": {"a"}, "V.2": {"b"}},
},
// custom delimiters
{
struct {
Expand Down