wip
This commit is contained in:
37
example/body/main.go
Normal file
37
example/body/main.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"nf"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := nf.New()
|
||||
|
||||
app.Post("/data", func(c *nf.Ctx) error {
|
||||
type Req struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
req = new(Req)
|
||||
rm = make(map[string]any)
|
||||
)
|
||||
|
||||
if err = c.BodyParser(req); err != nil {
|
||||
log.Print("err 1:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
if err = c.BodyParser(&rm); err != nil {
|
||||
log.Print("err 2:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
return c.JSON(nf.Map{"rm": rm, "req": req})
|
||||
})
|
||||
|
||||
log.Fatal(app.Run(":19991"))
|
||||
}
|
Reference in New Issue
Block a user