chore: remove print

This commit is contained in:
loveuer
2024-02-01 18:06:07 +08:00
parent 9dcf2f8e28
commit 1c9c21e294
3 changed files with 32 additions and 8 deletions

View File

@ -3,4 +3,12 @@ GET http://127.0.0.1/hello/nf
### test resp error
GET http://127.0.0.1/error
GET http://127.0.0.1/error
### test basic post
POST http://127.0.0.1/data
Content-Type: application/json
{
"name": "nice"
}

View File

@ -5,7 +5,6 @@ import (
"github.com/loveuer/nf"
"github.com/loveuer/nf/nft/resp"
"log"
"net"
"time"
)
@ -25,7 +24,27 @@ func main() {
app.Get("/error", func(c *nf.Ctx) error {
return resp.RespError(c, resp.NewError(404, "not found", errors.New("NNNot Found"), nil))
})
app.Post("/data", func(c *nf.Ctx) error {
type Req struct {
Name string `json:"name"`
}
ln, _ := net.Listen("tcp", ":80")
log.Fatal(app.RunListener(ln))
var (
err error
req = new(Req)
rm = make(map[string]any)
)
if err = c.BodyParser(req); err != nil {
return c.JSON(nf.Map{"status": 400, "msg": err.Error()})
}
if err = c.BodyParser(&rm); err != nil {
return c.JSON(nf.Map{"status": 400, "msg": err.Error()})
}
return c.JSON(nf.Map{"status": 200, "data": req, "map": rm})
})
log.Fatal(app.Run(":80"))
}