feat: make APIHandler consistent with other handlers

This commit is contained in:
2025-11-11 04:20:59 +01:00
parent 408b0000c8
commit 7518896cfe

View File

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