iris/_examples/http_request/read-yaml/main.go
Gerasimos (Makis) Maropoulos f3745cebbd replace all common error responses with the new Context.StopWithError
Former-commit-id: 99b08a0b5564ef640456db12674cb37721f73ae3
2020-05-18 00:25:38 +03:00

36 lines
614 B
Go

package main
import (
"github.com/kataras/iris/v12"
)
func newApp() *iris.Application {
app := iris.New()
app.Post("/", handler)
return app
}
// simple yaml stuff, read more at https://yaml.org/start.html
type product struct {
Invoice int `yaml:"invoice"`
Tax float32 `yaml:"tax"`
Total float32 `yaml:"total"`
Comments string `yaml:"comments"`
}
func handler(ctx iris.Context) {
var p product
if err := ctx.ReadYAML(&p); err != nil {
ctx.StopWithError(iris.StatusBadRequest, err)
return
}
ctx.Writef("Received: %#+v", p)
}
func main() {
app := newApp()
app.Listen(":8080")
}