oauth2-resource-server/cmd/api/routes.go
2025-01-02 15:13:41 +08:00

32 lines
803 B
Go

package main
import (
"expvar"
"net/http"
"github.com/julienschmidt/httprouter"
)
func (app *application) routes() http.Handler {
router := httprouter.New()
router.NotFound = http.HandlerFunc(app.notFoundResponse)
router.MethodNotAllowed = http.HandlerFunc(app.methodNotAllowResponse)
router.HandlerFunc(http.MethodGet, "/v1/healthcheck", app.healthcheckHandler)
// 授权
router.HandlerFunc(http.MethodGet, "/v1/login", app.loginHandler)
router.HandlerFunc(http.MethodGet, "/v1/oauth2", app.oauth2Handler)
router.HandlerFunc(http.MethodPost, "/v1/refresh-token", app.refreshTokenHandler)
router.Handler(http.MethodGet, "/debug/vars", expvar.Handler())
return app.metrics(
app.recoverPanic(
app.enableCORS(
app.rateLimit(
app.authenticate(router),
),
),
),
)
}