1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

refactor: replace gorilla mux with chi

This commit is contained in:
Ferdinand Mütsch
2023-03-03 20:40:50 +01:00
parent e495468be2
commit a6ef735ba1
32 changed files with 1407 additions and 1582 deletions

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"github.com/duke-git/lancet/v2/slice"
"github.com/emvi/logbuch"
"github.com/gorilla/mux"
"github.com/go-chi/chi/v5"
conf "github.com/muety/wakapi/config"
"github.com/muety/wakapi/middlewares"
"github.com/muety/wakapi/models"
@@ -34,16 +34,17 @@ func NewLeaderboardHandler(userService services.IUserService, leaderboardService
}
}
func (h *LeaderboardHandler) RegisterRoutes(router *mux.Router) {
r := router.PathPrefix("/leaderboard").Subrouter()
func (h *LeaderboardHandler) RegisterRoutes(router chi.Router) {
r := chi.NewRouter()
r.Use(
middlewares.NewAuthenticateMiddleware(h.userService).
WithRedirectTarget(defaultErrorRedirectTarget()).
WithRedirectErrorMessage("unauthorized").
WithOptionalFor([]string{"/"}).
Handler,
WithOptionalFor([]string{"/"}).Handler,
)
r.Methods(http.MethodGet).HandlerFunc(h.GetIndex)
r.Get("/", h.GetIndex)
router.Mount("/leaderboard", r)
}
func (h *LeaderboardHandler) GetIndex(w http.ResponseWriter, r *http.Request) {