This commit is contained in:
loveuer
2024-01-11 22:29:30 +08:00
parent 12ce2a4963
commit 161d16967f
15 changed files with 435 additions and 81 deletions

37
example/body/main.go Normal file
View 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"))
}