1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 10:27:06 +00:00

add examples for read using custom decoder per type, read using custom decoder via iris#UnmarshalerFunc and to complete it add an example for the context#ReadXML.

Former-commit-id: 536b1780f12d0b9d9ce9aa976a0f95f18634ec2d
This commit is contained in:
Gerasimos Maropoulos
2018-03-08 05:21:16 +02:00
parent 1a4803307d
commit 83c4b7f52d
14 changed files with 314 additions and 34 deletions

View File

@@ -11,16 +11,18 @@ type Company struct {
}
func MyHandler(ctx iris.Context) {
c := &Company{}
if err := ctx.ReadJSON(c); err != nil {
var c Company
if err := ctx.ReadJSON(&c); err != nil {
ctx.StatusCode(iris.StatusBadRequest)
ctx.WriteString(err.Error())
return
}
ctx.Writef("Received: %#v\n", c)
ctx.Writef("Received: %#+v\n", c)
}
// simple json stuff, read more at https://golang.org/pkg/encoding/json
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
@@ -55,9 +57,9 @@ func main() {
"Other": "Something here"
}
*/
// and Content-Type to application/json
// and Content-Type to application/json (optionally but good practise)
//
// The response should be:
// Received: &main.Company{Name:"iris-Go", City:"New York", Other:"Something here"}
app.Run(iris.Addr(":8080"))
// Received: main.Company{Name:"iris-Go", City:"New York", Other:"Something here"}
app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed), iris.WithOptimizations)
}