28 lines
725 B
Go
28 lines
725 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"booklib/internal/config"
|
|
"booklib/internal/redispkg"
|
|
"booklib/internal/store"
|
|
)
|
|
|
|
func NewRouter(cfg *config.Config, st *store.Store, rdb *redispkg.R) *gin.Engine {
|
|
gin.SetMode(gin.ReleaseMode)
|
|
a := &api{cfg: cfg, st: st, rdb: rdb}
|
|
r := gin.New()
|
|
r.Use(gin.Recovery())
|
|
g := r.Group("/api")
|
|
g.GET("/healthz", func(c *gin.Context) { c.String(http.StatusOK, "ok") })
|
|
g.POST("/auth/login", a.login)
|
|
|
|
p := g.Group("", a.authMw())
|
|
p.GET("/auth/me", a.me)
|
|
// ponytail: 501 垫片,Task 5 换成 a.createUser;无此路由则 member 403 测不到
|
|
p.POST("/users", a.adminOnly(), func(c *gin.Context) { c.Status(http.StatusNotImplemented) })
|
|
return r
|
|
}
|