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

@ -2,7 +2,7 @@ package api
import (
"codeberg.org/Codeberg/avatars"
"github.com/gorilla/mux"
"github.com/go-chi/chi/v5"
lru "github.com/hashicorp/golang-lru"
conf "github.com/muety/wakapi/config"
"github.com/muety/wakapi/utils"
@ -27,13 +27,12 @@ func NewAvatarHandler() *AvatarHandler {
}
}
func (h *AvatarHandler) RegisterRoutes(router *mux.Router) {
r := router.PathPrefix("/avatar/{hash}.svg").Subrouter()
r.Path("").Methods(http.MethodGet).HandlerFunc(h.Get)
func (h *AvatarHandler) RegisterRoutes(router chi.Router) {
router.Get("/avatar/{hash}.svg", h.Get)
}
func (h *AvatarHandler) Get(w http.ResponseWriter, r *http.Request) {
hash := mux.Vars(r)["hash"]
hash := chi.URLParam(r, "hash")
if utils.IsNoCache(r, 1*time.Hour) {
h.cache.Remove(hash)