-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
Request | ||
============ | ||
|
||
``Request`` is a wrapper of Go's built-in ``http.Request``. | ||
|
||
func (Request) Query | ||
************************ | ||
|
||
``func (req *Request) Query(key string, index ...int) (string, error)`` | ||
|
||
``Query`` returns query data by the query key.:: | ||
|
||
// GET /search?q=foo | ||
val, err := req.Query("q") | ||
// var == "foo", err == nil | ||
|
||
You can indicate an index for multiple query with the same key.:: | ||
|
||
// GET /search?q=foo&q=bar | ||
val, err := req.Query("q", 0) | ||
// var == "foo", err == nil | ||
val, err := req.Query("q", 1) | ||
// var == "bar", err == nil | ||
|
||
If there is no query matching the key, ``Query`` returns "".:: | ||
|
||
// GET /search?q=foo | ||
val, err := req.Query("m") | ||
// var == "", err != nil | ||
|
||
func (Request) Cookie | ||
********************* | ||
|
||
``func (req *Request) Cookie(key string) string`` | ||
|
||
``Cookie`` returns the cookie value from the request based on the given key:: | ||
|
||
// Cookie: name=foo | ||
req.Cookie("name") | ||
// "foo" | ||
|
||
|
||
func (Request) Protocol | ||
*********************** | ||
|
||
``func (req *Request) Protocol() string`` | ||
|
||
``Protocl`` returns the request protocol string.:: | ||
|
||
req.Protocol() | ||
// "HTTP/1.1" |