nf/example/simple/main.go
2024-01-11 18:16:41 +08:00

40 lines
611 B
Go

package main
import (
"errors"
"fmt"
"log"
"nf"
"time"
)
func main() {
app := nf.New()
app.Get("/hello", func(c *nf.Ctx) error {
return c.SendString("world")
})
app.Get("/world", func(c *nf.Ctx) error {
return errors.New("nice")
})
v1 := app.Group("/v1")
v1.Get("/hello", func(c *nf.Ctx) error {
return c.JSON(nf.Map{"version": "v1", "date": time.Now()})
})
v1.Get(
"/name",
func(c *nf.Ctx) error {
c.Params["name"] = "zyp"
return c.Next()
},
func(c *nf.Ctx) error {
return c.SendString(fmt.Sprintf("hi, %s", c.Params["name"]))
},
)
log.Fatal(app.Run(":7733"))
}