1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| package main
import ( "net/http" "github.com/gin-gonic/gin" )
func main() { r := gin.Default()
r.Use(auth())
g := r.Group("/v2")
g.Use(auth())
r.GET("/user", func(c *gin.Context) { uid := c.MustGet("uid")
c.String(http.StatusOK, uid.(string)) })
r.Run("127.0.0.1:9000") }
func auth() gin.HandlerFunc { ... }
|