-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
GH-5 add a query directive to pull values from querystring params #6
Conversation
the 'query' directive parses values out of the 'request.URL.Query()' values in the same way as the 'form' directive parses values out of the form body
Thanks a lot for this PR. Could you please confirm that if the |
I was surprised to learn that the unit test I added still passed after using the I am going to confirm that this works also in the web project I experienced the initial challenge, then will update this pr to demonstrate that the |
I think the name Now through your case I think that maybe other people have the same problem like yours. Thus the name If the name was the root cause leading to the misunderstanding. I propose to make an alias of the original |
I've reviewed this PR these days and have a conclusion here: The
Though it looks like the proposed The package main
import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"strings"
)
func PrintInput(rw http.ResponseWriter, r *http.Request) {
r.ParseForm()
fmt.Printf("ContentType: %#v\n", r.Header.Get("Content-Type"))
fmt.Printf("Form: %#v\n", r.Form)
fmt.Printf("Query: %#v\n", r.URL.Query())
}
func main() {
postForm := url.Values{}
postForm.Add("is_member", "false")
r2 := httptest.NewRequest(
"POST",
"http://example.com/users?page=5&page_size=20&is_member=true",
strings.NewReader(postForm.Encode()),
)
r2.Header.Add("Content-Type", "application/x-www-form-urlencoded")
w2 := httptest.NewRecorder()
PrintInput(w2, r2)
} Output:
Finally, I would like to merge this pull request and give some detail explanations in the documentation. @davidalpert Thanks again :) |
@@ -60,11 +60,12 @@ func ListUsers(rw http.ResponseWriter, r *http.Request) { | |||
|
|||
## Features | |||
|
|||
- [x] Builtin directive `form` to decode a field from HTTP query (URL params), i.e. `http.Request.Form` | |||
- [x] Builtin directive `form` to decode a field from HTTP form values, i.e. `http.Request.Form` | |||
- [x] Builtin directive `query` to decode a field from HTTP querystring parameters, i.e. `http.Request.URL.Query()` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think query
is used more frequently than the other directives. It's better to be documented at the first place. And we can tell something about the difference between form
and query
or simply link to the conversation of this PR.
Thank you for considering this PR and explaining that By having the Documentation can be tricky to get right while iterating through a pull request. Would you like to update the readme directly in this branch? Feel free to take this PR, adjust it as you like, and merge it when you feel it is complete. |
@ggicci would you be willing to add a I am participating in Digital Ocean's Hacktoberfest this year and that label will allow this PR to be recognized as a Hacktoberfest contribution. |
sure |
No description provided.