2024-01-12 19:18:33 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/loveuer/nf"
|
|
|
|
"log"
|
2024-01-13 17:45:44 +08:00
|
|
|
"net"
|
2024-01-14 19:10:05 +08:00
|
|
|
"time"
|
2024-01-12 19:18:33 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := nf.New()
|
|
|
|
|
|
|
|
app.Get("/hello/:name", func(c *nf.Ctx) error {
|
|
|
|
name := c.Param("name")
|
|
|
|
return c.JSON(nf.Map{"status": 200, "data": "hello, " + name})
|
|
|
|
})
|
2024-01-14 19:10:05 +08:00
|
|
|
app.Patch("/world", func(c *nf.Ctx) error {
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
c.Status(404)
|
|
|
|
return c.JSON(nf.Map{"method": c.Method, "status": c.StatusCode})
|
|
|
|
})
|
2024-01-12 19:18:33 +08:00
|
|
|
|
2024-01-13 17:45:44 +08:00
|
|
|
ln, _ := net.Listen("tcp", ":80")
|
|
|
|
log.Fatal(app.RunListener(ln))
|
2024-01-12 19:18:33 +08:00
|
|
|
}
|