1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-23 21:07:03 +00:00

Version 3.0.0-beta cleaned

This commit is contained in:
Makis Maropoulos
2016-05-30 17:08:09 +03:00
commit c26668a489
114 changed files with 14552 additions and 0 deletions

25
bindings/json.go Normal file
View File

@@ -0,0 +1,25 @@
package bindings
import (
"encoding/json"
"io"
"strings"
"github.com/kataras/iris/context"
)
// BindJSON reads JSON from request's body
func BindJSON(ctx context.IContext, jsonObject interface{}) error {
data := ctx.GetRequestCtx().Request.Body()
decoder := json.NewDecoder(strings.NewReader(string(data)))
err := decoder.Decode(jsonObject)
//err != nil fix by @shiena
if err != nil && err != io.EOF {
return ErrReadBody.Format("JSON", err.Error())
}
return nil
}