mirror of
https://github.com/kataras/iris.git
synced 2026-03-06 08:25:59 +00:00
reorganization of _examples and add some new examples such as iris+groupcache+mysql+docker
Former-commit-id: ed635ee95de7160cde11eaabc0c1dcb0e460a620
This commit is contained in:
35
_examples/request-body/read-yaml/main.go
Normal file
35
_examples/request-body/read-yaml/main.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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")
|
||||
}
|
||||
Reference in New Issue
Block a user