mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
parent
910315ec5f
commit
7741bd0125
14
context.go
14
context.go
@ -56,10 +56,16 @@ type (
|
||||
// for `engine.URL#QueryParam()`.
|
||||
QueryParam(string) string
|
||||
|
||||
// QueryParam returns the query parameters as map. It is an alias for `engine.URL#QueryParams()`.
|
||||
QueryParams() map[string][]string
|
||||
|
||||
// FormValue returns the form field value for the provided name. It is an
|
||||
// alias for `engine.Request#FormValue()`.
|
||||
FormValue(string) string
|
||||
|
||||
// FormParams returns the form parameters as map. It is an alias for `engine.Request#FormParams()`.
|
||||
FormParams() map[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)
|
||||
@ -235,10 +241,18 @@ func (c *context) QueryParam(name string) string {
|
||||
return c.request.URL().QueryParam(name)
|
||||
}
|
||||
|
||||
func (c *context) QueryParams() map[string][]string {
|
||||
return c.request.URL().QueryParams()
|
||||
}
|
||||
|
||||
func (c *context) FormValue(name string) string {
|
||||
return c.request.FormValue(name)
|
||||
}
|
||||
|
||||
func (c *context) FormParams() map[string][]string {
|
||||
return c.request.FormParams()
|
||||
}
|
||||
|
||||
func (c *context) FormFile(name string) (*multipart.FileHeader, error) {
|
||||
return c.request.FormFile(name)
|
||||
}
|
||||
|
@ -66,6 +66,9 @@ type (
|
||||
// FormValue returns the form field value for the provided name.
|
||||
FormValue(string) string
|
||||
|
||||
// FormParams returns the form parameters.
|
||||
FormParams() map[string][]string
|
||||
|
||||
// FormFile returns the multipart form file for the provided name.
|
||||
FormFile(string) (*multipart.FileHeader, error)
|
||||
|
||||
@ -132,6 +135,9 @@ type (
|
||||
// QueryParam returns the query param for the provided name.
|
||||
QueryParam(string) string
|
||||
|
||||
// QueryParam returns the query parameters as map.
|
||||
QueryParams() map[string][]string
|
||||
|
||||
// QueryString returns the URL query string.
|
||||
QueryString() string
|
||||
}
|
||||
|
@ -82,6 +82,16 @@ func (r *Request) FormValue(name string) string {
|
||||
return string(r.RequestCtx.FormValue(name))
|
||||
}
|
||||
|
||||
// FormParams implements `engine.Request#FormParams` function.
|
||||
func (r *Request) FormParams() (params map[string][]string) {
|
||||
params = make(map[string][]string)
|
||||
r.PostArgs().VisitAll(func(k, v []byte) {
|
||||
// TODO: Filling with only first value
|
||||
params[string(k)] = []string{string(v)}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// FormFile implements `engine.Request#FormFile` function.
|
||||
func (r *Request) FormFile(name string) (*multipart.FileHeader, error) {
|
||||
return r.RequestCtx.FormFile(name)
|
||||
|
@ -26,6 +26,16 @@ func (u *URL) QueryParam(name string) string {
|
||||
return string(u.QueryArgs().Peek(name))
|
||||
}
|
||||
|
||||
// QueryParams implements `engine.URL#QueryParams` function.
|
||||
func (u *URL) QueryParams() (params map[string][]string) {
|
||||
params = make(map[string][]string)
|
||||
u.QueryArgs().VisitAll(func(k, v []byte) {
|
||||
// TODO: Filling with only first value
|
||||
params[string(k)] = []string{string(v)}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// QueryString implements `engine.URL#QueryString` function.
|
||||
func (u *URL) QueryString() string {
|
||||
return string(u.URI.QueryString())
|
||||
|
@ -2,6 +2,7 @@ package standard
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
|
||||
@ -14,6 +15,7 @@ type (
|
||||
*http.Request
|
||||
url engine.URL
|
||||
header engine.Header
|
||||
logger *log.Logger
|
||||
}
|
||||
)
|
||||
|
||||
@ -92,6 +94,14 @@ func (r *Request) FormValue(name string) string {
|
||||
return r.Request.FormValue(name)
|
||||
}
|
||||
|
||||
// FormParams implements `engine.Request#FormParams` function.
|
||||
func (r *Request) FormParams() map[string][]string {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
r.logger.Error(err)
|
||||
}
|
||||
return map[string][]string(r.Request.PostForm)
|
||||
}
|
||||
|
||||
// FormFile implements `engine.Request#FormFile` function.
|
||||
func (r *Request) FormFile(name string) (*multipart.FileHeader, error) {
|
||||
_, fh, err := r.Request.FormFile(name)
|
||||
@ -100,7 +110,7 @@ func (r *Request) FormFile(name string) (*multipart.FileHeader, error) {
|
||||
|
||||
// MultipartForm implements `engine.Request#MultipartForm` function.
|
||||
func (r *Request) MultipartForm() (*multipart.Form, error) {
|
||||
err := r.Request.ParseMultipartForm(32 << 20) // 32 MB
|
||||
err := r.ParseMultipartForm(32 << 20) // 32 MB
|
||||
return r.Request.MultipartForm, err
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ func NewFromConfig(c engine.Config) (s *Server) {
|
||||
pool: &pool{
|
||||
request: sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &Request{}
|
||||
return &Request{logger: s.logger}
|
||||
},
|
||||
},
|
||||
response: sync.Pool{
|
||||
|
@ -28,6 +28,14 @@ func (u *URL) QueryParam(name string) string {
|
||||
return u.query.Get(name)
|
||||
}
|
||||
|
||||
// QueryParams implements `engine.URL#QueryParams` function.
|
||||
func (u *URL) QueryParams() map[string][]string {
|
||||
if u.query == nil {
|
||||
u.query = u.Query()
|
||||
}
|
||||
return map[string][]string(u.query)
|
||||
}
|
||||
|
||||
// QueryString implements `engine.URL#QueryString` function.
|
||||
func (u *URL) QueryString() string {
|
||||
return u.URL.RawQuery
|
||||
|
@ -88,6 +88,11 @@ func (r *Request) FormValue(name string) string {
|
||||
return r.request.FormValue(name)
|
||||
}
|
||||
|
||||
func (r *Request) FormParams() map[string][]string {
|
||||
r.request.ParseForm()
|
||||
return map[string][]string(r.request.PostForm)
|
||||
}
|
||||
|
||||
func (r *Request) FormFile(name string) (*multipart.FileHeader, error) {
|
||||
_, fh, err := r.request.FormFile(name)
|
||||
return fh, err
|
||||
|
@ -28,6 +28,13 @@ func (u *URL) QueryParam(name string) string {
|
||||
return u.query.Get(name)
|
||||
}
|
||||
|
||||
func (u *URL) QueryParams() map[string][]string {
|
||||
if u.query == nil {
|
||||
u.query = u.url.Query()
|
||||
}
|
||||
return map[string][]string(u.query)
|
||||
}
|
||||
|
||||
func (u *URL) QueryString() string {
|
||||
return u.url.RawQuery
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user