chore: update go module, readme
This commit is contained in:
parent
5263cba44a
commit
66d48d631e
35
readme.md
35
readme.md
@ -5,6 +5,7 @@
|
||||
##### basic usage
|
||||
|
||||
- get param
|
||||
|
||||
```go
|
||||
func main() {
|
||||
app := nf.New()
|
||||
@ -19,6 +20,7 @@ func main() {
|
||||
```
|
||||
|
||||
- parse request query
|
||||
|
||||
```go
|
||||
func handleQuery(c *nf.Ctx) error {
|
||||
type Req struct {
|
||||
@ -40,6 +42,7 @@ func handleQuery(c *nf.Ctx) error {
|
||||
```
|
||||
|
||||
- parse application/json body
|
||||
|
||||
```go
|
||||
func handlePost(c *nf.Ctx) error {
|
||||
type Req struct {
|
||||
@ -65,3 +68,35 @@ func handlePost(c *nf.Ctx) error {
|
||||
return c.JSON(nf.Map{"struct": req, "map": reqMap})
|
||||
}
|
||||
```
|
||||
|
||||
- pass local value
|
||||
|
||||
```go
|
||||
type User struct {
|
||||
Id int
|
||||
Username string
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := nf.New()
|
||||
app.Use(auth())
|
||||
|
||||
app.Get("/item/list", list)
|
||||
}
|
||||
|
||||
func auth() nf.HandlerFunc {
|
||||
return func(c *nf.Ctx) error {
|
||||
c.Locals("user", &User{Id: 1, Username:"user"})
|
||||
return c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
func list(c *nf.Ctx) error {
|
||||
user, ok := c.Locals("user").(*User)
|
||||
if !ok {
|
||||
return c.Status(401).SendString("login required")
|
||||
}
|
||||
|
||||
...
|
||||
}
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user