go-jwtserver/internal/router/router.go

32 lines
685 B
Go

package router
import (
"time"
jwtmiddleware "forge.cadoles.com/mlamalle/go-jwtserver/middleware"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
)
func InitializeRouter() chi.Router {
r := chi.NewRouter()
// Define base middlewares
r.Use(middleware.RequestID)
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Use(middleware.URLFormat)
r.Use(jwtmiddleware.JwtAuthentication)
r.Use(middleware.Timeout(60 * time.Second))
r.Route("/api/", func(r chi.Router) {
// Middleware routes
r.Post("/user/new", jwtmiddleware.CreateAccount)
r.Post("/user/login", jwtmiddleware.Authenticate)
r.Post("/user/refresh", jwtmiddleware.Refresh)
})
return r
}