diff --git a/context.go b/context.go index 78eb197a..878c4804 100644 --- a/context.go +++ b/context.go @@ -5,6 +5,7 @@ import ( "encoding/xml" "io" "mime" + "mime/multipart" "net/http" "os" "path" @@ -51,11 +52,20 @@ type ( // ParamNames returns path parameter names. ParamNames() []string - // Query returns query parameter by name. - Query(string) string + // QueryParam returns the query param for the provided name. It is an alias + // for `engine.URL#QueryParam()`. + QueryParam(string) string - // Form returns form parameter by name. - Form(string) string + // FormValue returns the form field value for the provided name. It is an + // alias for `engine.Request#FormValue()`. + FormValue(string) string + + // FormFile returns the multipart form file for the provided name. It is an + // alias for `engine.Request#FormFile()`. + FormFile(string) (*multipart.FileHeader, error) + + // MultipartForm returns the multipart form. It is an alias for `engine.Request#MultipartForm()`. + MultipartForm() (*multipart.Form, error) // Get retrieves data from the context. Get(string) interface{} @@ -221,14 +231,22 @@ func (c *context) ParamNames() []string { return c.pnames } -func (c *context) Query(name string) string { - return c.request.URL().QueryValue(name) +func (c *context) QueryParam(name string) string { + return c.request.URL().QueryParam(name) } -func (c *context) Form(name string) string { +func (c *context) FormValue(name string) string { return c.request.FormValue(name) } +func (c *context) FormFile(name string) (*multipart.FileHeader, error) { + return c.request.FormFile(name) +} + +func (c *context) MultipartForm() (*multipart.Form, error) { + return c.request.MultipartForm() +} + func (c *context) Set(key string, val interface{}) { if c.store == nil { c.store = make(store) diff --git a/context_test.go b/context_test.go index 1c4f7ed8..e38aad16 100644 --- a/context_test.go +++ b/context_test.go @@ -210,17 +210,17 @@ func TestContextPath(t *testing.T) { assert.Equal(t, "/users/:uid/files/:fid", c.Path()) } -func TestContextQuery(t *testing.T) { +func TestContextQueryParam(t *testing.T) { q := make(url.Values) q.Set("name", "joe") q.Set("email", "joe@labstack.com") req := test.NewRequest(GET, "/?"+q.Encode(), nil) c := NewContext(req, nil, New()) - assert.Equal(t, "joe", c.Query("name")) - assert.Equal(t, "joe@labstack.com", c.Query("email")) + assert.Equal(t, "joe", c.QueryParam("name")) + assert.Equal(t, "joe@labstack.com", c.QueryParam("email")) } -func TestContextForm(t *testing.T) { +func TestContextFormValue(t *testing.T) { f := make(url.Values) f.Set("name", "joe") f.Set("email", "joe@labstack.com") @@ -229,8 +229,8 @@ func TestContextForm(t *testing.T) { req.Header().Add(ContentType, ApplicationForm) c := NewContext(req, nil, New()) - assert.Equal(t, "joe", c.Form("name")) - assert.Equal(t, "joe@labstack.com", c.Form("email")) + assert.Equal(t, "joe", c.FormValue("name")) + assert.Equal(t, "joe@labstack.com", c.FormValue("email")) } func TestContextNetContext(t *testing.T) { diff --git a/engine/engine.go b/engine/engine.go index a5526030..34a1241d 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -63,13 +63,13 @@ type ( // Body returns request's body. Body() io.Reader - // FormValue returns form field value for the provided name. + // FormValue returns the form field value for the provided name. FormValue(string) string - // FormFile returns form file for the provided name. + // FormFile returns the multipart form file for the provided name. FormFile(string) (*multipart.FileHeader, error) - // MultipartForm returns multipart form. + // MultipartForm returns the multipart form. MultipartForm() (*multipart.Form, error) } @@ -129,8 +129,8 @@ type ( // SetPath sets the request URL path. SetPath(string) - // QueryValue returns query parameter value for the provided name. - QueryValue(string) string + // QueryParam returns the query param for the provided name. + QueryParam(string) string // QueryString returns the URL query string. QueryString() string diff --git a/engine/fasthttp/url.go b/engine/fasthttp/url.go index 75dbedad..33237bd0 100644 --- a/engine/fasthttp/url.go +++ b/engine/fasthttp/url.go @@ -21,8 +21,8 @@ func (u *URL) SetPath(path string) { u.URI.SetPath(path) } -// QueryValue implements `engine.URL#QueryValue` function. -func (u *URL) QueryValue(name string) string { +// QueryParam implements `engine.URL#QueryParam` function. +func (u *URL) QueryParam(name string) string { return string(u.QueryArgs().Peek(name)) } diff --git a/engine/standard/url.go b/engine/standard/url.go index b382861e..ab5e8d7c 100644 --- a/engine/standard/url.go +++ b/engine/standard/url.go @@ -20,8 +20,8 @@ func (u *URL) SetPath(path string) { u.URL.Path = path } -// QueryValue implements `engine.URL#QueryValue` function. -func (u *URL) QueryValue(name string) string { +// QueryParam implements `engine.URL#QueryParam` function. +func (u *URL) QueryParam(name string) string { if u.query == nil { u.query = u.Query() } diff --git a/test/url.go b/test/url.go index 57a7d036..9b7d0605 100644 --- a/test/url.go +++ b/test/url.go @@ -21,7 +21,7 @@ func (u *URL) Path() string { return u.url.Path } -func (u *URL) QueryValue(name string) string { +func (u *URL) QueryParam(name string) string { if u.query == nil { u.query = u.url.Query() }