Compare commits

...

2 Commits

Author SHA1 Message Date
7518896cfe feat: make APIHandler consistent with other handlers 2025-11-11 04:20:59 +01:00
408b0000c8 feat: mount /api in API handler 2025-11-11 04:20:03 +01:00
2 changed files with 11 additions and 7 deletions

View File

@@ -256,4 +256,9 @@ func (h *APIHandler) GetMetrics(w http.ResponseWriter, r *http.Request) {
}
func (h *APIHandler) MountRoutes(r chi.Router, config RouteModuleConfig) {
public := r
if config.GeneralRateLimit != nil {
public = config.GeneralRateLimit(r)
}
public.Get("/", h.GetAPIInfo)
}

View File

@@ -5,11 +5,12 @@ import (
"path/filepath"
"time"
"github.com/go-chi/chi/v5"
httpSwagger "github.com/swaggo/http-swagger"
"goyco/internal/config"
"goyco/internal/handlers"
"goyco/internal/middleware"
"github.com/go-chi/chi/v5"
httpSwagger "github.com/swaggo/http-swagger"
)
type RouterConfig struct {
@@ -108,15 +109,13 @@ func NewRouter(cfg RouterConfig) http.Handler {
if cfg.UserHandler != nil {
modules = append(modules, cfg.UserHandler)
}
if cfg.APIHandler != nil {
modules = append(modules, cfg.APIHandler)
}
for _, module := range modules {
module.MountRoutes(api, routeConfig)
}
if cfg.APIHandler != nil {
apiRateLimited := api.With(middleware.GeneralRateLimitMiddlewareWithLimit(cfg.RateLimitConfig.GeneralLimit))
apiRateLimited.Get("/", cfg.APIHandler.GetAPIInfo)
}
})
staticDir := cfg.StaticDir