Skip to content

Commit 703174e

Browse files
committed
Context#Form() > Context#FormValue(), Context#Query() > Context#QueryParam()
Signed-off-by: Vishal Rana <[email protected]>
1 parent 3d656d1 commit 703174e

File tree

6 files changed

+41
-23
lines changed

6 files changed

+41
-23
lines changed

context.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/xml"
66
"io"
77
"mime"
8+
"mime/multipart"
89
"net/http"
910
"os"
1011
"path"
@@ -51,11 +52,20 @@ type (
5152
// ParamNames returns path parameter names.
5253
ParamNames() []string
5354

54-
// Query returns query parameter by name.
55-
Query(string) string
55+
// QueryParam returns the query param for the provided name. It is an alias
56+
// for `engine.URL#QueryParam()`.
57+
QueryParam(string) string
5658

57-
// Form returns form parameter by name.
58-
Form(string) string
59+
// FormValue returns the form field value for the provided name. It is an
60+
// alias for `engine.Request#FormValue()`.
61+
FormValue(string) string
62+
63+
// FormFile returns the multipart form file for the provided name. It is an
64+
// alias for `engine.Request#FormFile()`.
65+
FormFile(string) (*multipart.FileHeader, error)
66+
67+
// MultipartForm returns the multipart form. It is an alias for `engine.Request#MultipartForm()`.
68+
MultipartForm() (*multipart.Form, error)
5969

6070
// Get retrieves data from the context.
6171
Get(string) interface{}
@@ -221,14 +231,22 @@ func (c *context) ParamNames() []string {
221231
return c.pnames
222232
}
223233

224-
func (c *context) Query(name string) string {
225-
return c.request.URL().QueryValue(name)
234+
func (c *context) QueryParam(name string) string {
235+
return c.request.URL().QueryParam(name)
226236
}
227237

228-
func (c *context) Form(name string) string {
238+
func (c *context) FormValue(name string) string {
229239
return c.request.FormValue(name)
230240
}
231241

242+
func (c *context) FormFile(name string) (*multipart.FileHeader, error) {
243+
return c.request.FormFile(name)
244+
}
245+
246+
func (c *context) MultipartForm() (*multipart.Form, error) {
247+
return c.request.MultipartForm()
248+
}
249+
232250
func (c *context) Set(key string, val interface{}) {
233251
if c.store == nil {
234252
c.store = make(store)

context_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,17 @@ func TestContextPath(t *testing.T) {
210210
assert.Equal(t, "/users/:uid/files/:fid", c.Path())
211211
}
212212

213-
func TestContextQuery(t *testing.T) {
213+
func TestContextQueryParam(t *testing.T) {
214214
q := make(url.Values)
215215
q.Set("name", "joe")
216216
q.Set("email", "[email protected]")
217217
req := test.NewRequest(GET, "/?"+q.Encode(), nil)
218218
c := NewContext(req, nil, New())
219-
assert.Equal(t, "joe", c.Query("name"))
220-
assert.Equal(t, "[email protected]", c.Query("email"))
219+
assert.Equal(t, "joe", c.QueryParam("name"))
220+
assert.Equal(t, "[email protected]", c.QueryParam("email"))
221221
}
222222

223-
func TestContextForm(t *testing.T) {
223+
func TestContextFormValue(t *testing.T) {
224224
f := make(url.Values)
225225
f.Set("name", "joe")
226226
f.Set("email", "[email protected]")
@@ -229,8 +229,8 @@ func TestContextForm(t *testing.T) {
229229
req.Header().Add(ContentType, ApplicationForm)
230230

231231
c := NewContext(req, nil, New())
232-
assert.Equal(t, "joe", c.Form("name"))
233-
assert.Equal(t, "[email protected]", c.Form("email"))
232+
assert.Equal(t, "joe", c.FormValue("name"))
233+
assert.Equal(t, "[email protected]", c.FormValue("email"))
234234
}
235235

236236
func TestContextNetContext(t *testing.T) {

engine/engine.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ type (
6363
// Body returns request's body.
6464
Body() io.Reader
6565

66-
// FormValue returns form field value for the provided name.
66+
// FormValue returns the form field value for the provided name.
6767
FormValue(string) string
6868

69-
// FormFile returns form file for the provided name.
69+
// FormFile returns the multipart form file for the provided name.
7070
FormFile(string) (*multipart.FileHeader, error)
7171

72-
// MultipartForm returns multipart form.
72+
// MultipartForm returns the multipart form.
7373
MultipartForm() (*multipart.Form, error)
7474
}
7575

@@ -129,8 +129,8 @@ type (
129129
// SetPath sets the request URL path.
130130
SetPath(string)
131131

132-
// QueryValue returns query parameter value for the provided name.
133-
QueryValue(string) string
132+
// QueryParam returns the query param for the provided name.
133+
QueryParam(string) string
134134

135135
// QueryString returns the URL query string.
136136
QueryString() string

engine/fasthttp/url.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ func (u *URL) SetPath(path string) {
2121
u.URI.SetPath(path)
2222
}
2323

24-
// QueryValue implements `engine.URL#QueryValue` function.
25-
func (u *URL) QueryValue(name string) string {
24+
// QueryParam implements `engine.URL#QueryParam` function.
25+
func (u *URL) QueryParam(name string) string {
2626
return string(u.QueryArgs().Peek(name))
2727
}
2828

engine/standard/url.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func (u *URL) SetPath(path string) {
2020
u.URL.Path = path
2121
}
2222

23-
// QueryValue implements `engine.URL#QueryValue` function.
24-
func (u *URL) QueryValue(name string) string {
23+
// QueryParam implements `engine.URL#QueryParam` function.
24+
func (u *URL) QueryParam(name string) string {
2525
if u.query == nil {
2626
u.query = u.Query()
2727
}

test/url.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (u *URL) Path() string {
2121
return u.url.Path
2222
}
2323

24-
func (u *URL) QueryValue(name string) string {
24+
func (u *URL) QueryParam(name string) string {
2525
if u.query == nil {
2626
u.query = u.url.Query()
2727
}

0 commit comments

Comments
 (0)