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

Comments

@zheeeng
Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Feb 28, 2019

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

@zheeeng

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Owner

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

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Owner

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 added a commit that referenced this issue Jul 24, 2019

@kataras kataras closed this Aug 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.