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

[Context API Request] Add ReadQuery for convenient obtain query struct. #1207

Closed
zheeeng opened this issue Feb 28, 2019 · 5 comments
Closed

Comments

@zheeeng
Copy link

zheeeng commented Feb 28, 2019

example code:

type Query structure {
    Foo *string `url:"foo"`
    Bar *int `url:"bar"`
}

// in handler, assume the path is: api.example.com/path?foo=hello&bar=42

func (c iris.Context) {
    q := Query{}
    err := c.ReadQuery(&Query) 
    fmt.Println(c.foo == "hello")  // true
    fmt.Println(c.bar == 42)  // true
}
@Dexus
Copy link

Dexus commented Feb 28, 2019

This would be nice if it also support multiple same key values like ?a=car&a=motorcycle

@zheeeng
Copy link
Author

zheeeng commented Feb 28, 2019

This would be nice if it also support multiple same key values like ?a=car&a=motorcycle

Yeah, it should depend on that is the structure with 'a' is slice type or not.

@kataras
Copy link
Owner

kataras commented Mar 1, 2019

Hello @zheeeng and @Dexus did you try the ReadForm? if it is a get request it should be reading from queries.

@zheeeng
Copy link
Author

zheeeng commented Mar 1, 2019

Hello @zheeeng and @Dexus did you try the ReadForm? if it is a get request it should be reading from queries.

Seems that we can't rule the case conversion by tags? I tried github.com/gorilla/schema and it satisfies my demands.

@kataras
Copy link
Owner

kataras commented Jul 24, 2019

Done @zheeeng and @Dexus on 11.2.1 as you exactly requested:

ReadQuery // with "url" tag name, strictly as you requested.
ReadForm // stays with "form" tag name, strictly.

kataras added a commit that referenced this issue Jul 24, 2019
@kataras kataras closed this as completed Aug 14, 2019
github-actions bot pushed a commit to goproxies/github.com-kataras-iris that referenced this issue Jul 27, 2020
…uested at: kataras#1207

Former-commit-id: dc0c237f62aa6db5a0c1755b2074d8a18dba0d8f
github-actions bot pushed a commit to goproxies/github.com-kataras-iris that referenced this issue Jul 27, 2020
Former-commit-id: fca9db43ad6d78fcf01acf8edeadc12abc34195f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants