mirror of
https://github.com/kataras/iris.git
synced 2025-03-14 08:16:28 +01:00
context#ReadForm
: do not return an error if request data are not there, instead return nil without touching the ptr value. Requested at: https://github.com/kataras/iris/issues/1095
Former-commit-id: 9662854b3242b91ccb74d6adca72cdcb61689bd8
This commit is contained in:
parent
0f2c5da7df
commit
29a4354e1d
|
@ -560,7 +560,8 @@ type Context interface {
|
||||||
// Example: https://github.com/kataras/iris/blob/master/_examples/http_request/read-xml/main.go
|
// Example: https://github.com/kataras/iris/blob/master/_examples/http_request/read-xml/main.go
|
||||||
ReadXML(xmlObjectPtr interface{}) error
|
ReadXML(xmlObjectPtr interface{}) error
|
||||||
// ReadForm binds the formObject with the form data
|
// ReadForm binds the formObject with the form data
|
||||||
// it supports any kind of struct.
|
// it supports any kind of type, including custom structs.
|
||||||
|
// It will return nothing if request data are empty.
|
||||||
//
|
//
|
||||||
// Example: https://github.com/kataras/iris/blob/master/_examples/http_request/read-form/main.go
|
// Example: https://github.com/kataras/iris/blob/master/_examples/http_request/read-form/main.go
|
||||||
ReadForm(formObjectPtr interface{}) error
|
ReadForm(formObjectPtr interface{}) error
|
||||||
|
@ -2289,17 +2290,15 @@ var (
|
||||||
errReadBody = errors.New("while trying to read %s from the request body. Trace %s")
|
errReadBody = errors.New("while trying to read %s from the request body. Trace %s")
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrEmptyForm will be thrown from `context#ReadForm` when empty request data.
|
|
||||||
var ErrEmptyForm = errors.New("form data: empty")
|
|
||||||
|
|
||||||
// ReadForm binds the formObject with the form data
|
// ReadForm binds the formObject with the form data
|
||||||
// it supports any kind of struct.
|
// it supports any kind of type, including custom structs.
|
||||||
|
// It will return nothing if request data are empty.
|
||||||
//
|
//
|
||||||
// Example: https://github.com/kataras/iris/blob/master/_examples/http_request/read-form/main.go
|
// Example: https://github.com/kataras/iris/blob/master/_examples/http_request/read-form/main.go
|
||||||
func (ctx *context) ReadForm(formObject interface{}) error {
|
func (ctx *context) ReadForm(formObject interface{}) error {
|
||||||
values := ctx.FormValues()
|
values := ctx.FormValues()
|
||||||
if values == nil {
|
if len(values) == 0 {
|
||||||
return ErrEmptyForm
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// or dec := formbinder.NewDecoder(&formbinder.DecoderOptions{TagName: "form"})
|
// or dec := formbinder.NewDecoder(&formbinder.DecoderOptions{TagName: "form"})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user