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

feat: support query value list/array as url parameter #4015

Closed
wants to merge 1 commit into from

Conversation

ch3nnn
Copy link
Contributor

@ch3nnn ch3nnn commented Mar 19, 2024

Sending via URL:
List of values can be passed via URL like this:

http://localhost:8080/test/?userId=1&userId=2&username=admin&password=

OR

http://localhost:8080/test/?userId=[1,2]&username=admin

help to review it. thank! @kevwan @kesonan

@ch3nnn
Copy link
Contributor Author

ch3nnn commented Mar 29, 2024

I find current version support http://localhost:8080/test/?userId=[1,2]&username=["admin", "zhangsan"]

@ch3nnn ch3nnn closed this Mar 29, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I find current version support http://localhost:8080/test/?userId=[1,2]&username=["admin", "zhangsan"]

@ch3nnn
Copy link
Contributor Author

ch3nnn commented Apr 1, 2024

v1.6.3 support.

https://github.com/zeromicro/go-zero/blob/v1.6.3/rest/httpx/requests_test.go#L17

func TestParseForm(t *testing.T) {
	var v struct {
		Name    string   `form:"name"`
		Age     int      `form:"age"`
		Percent float64  `form:"percent,optional"`
		Role    []string `form:"role"`
		Ids     []int64  `form:"ids"`
	}

	r, err := http.NewRequest(http.MethodGet, `/a?name=hello&age=18&percent=3.4&role=["admin", "teacher", "student"]&ids=[1]`, http.NoBody)
	assert.Nil(t, err)
	assert.Nil(t, Parse(r, &v))
	assert.Equal(t, "hello", v.Name)
	assert.Equal(t, 18, v.Age)
	assert.Equal(t, 3.4, v.Percent)
	assert.Equal(t, 3, len(v.Role))
	assert.Equal(t, []string{"admin", "teacher", "student"}, v.Role)
	assert.Equal(t, []int64{1}, v.Ids)
}

unit test pass

=== RUN   TestParseForm
--- PASS: TestParseForm (0.00s)
PASS

need attention parse []string format url keyword must be included with ""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants