Compare commits
2 Commits
ab4da45de2
...
7518896cfe
| Author | SHA1 | Date | |
|---|---|---|---|
| 7518896cfe | |||
| 408b0000c8 |
@@ -256,4 +256,9 @@ func (h *APIHandler) GetMetrics(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *APIHandler) MountRoutes(r chi.Router, config RouteModuleConfig) {
|
func (h *APIHandler) MountRoutes(r chi.Router, config RouteModuleConfig) {
|
||||||
|
public := r
|
||||||
|
if config.GeneralRateLimit != nil {
|
||||||
|
public = config.GeneralRateLimit(r)
|
||||||
|
}
|
||||||
|
public.Get("/", h.GetAPIInfo)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user