mirror of
https://github.com/labstack/echo.git
synced 2025-07-15 01:34:53 +02:00
Context#Form() > Context#FormValue(), Context#Query() > Context#QueryParam()
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
32
context.go
32
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)
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
Reference in New Issue
Block a user