refactor!: Use gin router instead chi router

- Removed chi dependencies
- Updated router registration logic
This commit is contained in:
2025-11-04 13:44:18 +03:00
parent 7e9653606e
commit 7bc4ce8c96
13 changed files with 499 additions and 294 deletions

View File

@@ -11,39 +11,48 @@ import (
"git.ostiwe.com/ostiwe-com/status/router/controller/ping"
"git.ostiwe.com/ostiwe-com/status/router/controller/service"
"git.ostiwe.com/ostiwe-com/status/version"
"github.com/gin-gonic/gin"
"github.com/go-andiamo/chioas"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)
func getControllers() []controller.Controller {
return []controller.Controller{
new(ping.Controller).New(),
new(service.Controller).New(),
new(auth.Controller).New(),
new(service.GetServices).New(),
new(auth.PlainAuthController).New(),
}
}
func InitRoutes() *chi.Mux {
func InitRoutes() *gin.Engine {
log.Global.Get(log.SERVER).Info("Setting up routers")
startTime := time.Now()
httpLogger := middleware.RequestLogger(&middleware.DefaultLogFormatter{Logger: log.Global.Get(log.SERVER), NoColor: false})
r := chi.NewRouter()
r.Use(httpLogger)
r := gin.New()
r.Use(
middleware.RequestID,
middleware.RealIP,
middleware.StripSlashes,
middleware.Recoverer,
middleware.CleanPath,
middleware.Timeout(15*time.Second),
gin.Recovery(),
gin.LoggerWithConfig(gin.LoggerConfig{
Output: log.Global.Get(log.SERVER).Out,
}),
)
ctrlList := getControllers()
for _, ctrl := range ctrlList {
r.Group(ctrl.Group)
secured, ok := ctrl.(controller.SecuredController)
if ok {
r.Handle(
ctrl.Method(),
ctrl.Path(),
append(secured.Middlewares(), ctrl.Handler())...,
)
continue
}
r.Handle(
ctrl.Method(),
ctrl.Path(),
ctrl.Handler(),
)
}
log.Global.Get(log.SERVER).Info(fmt.Sprintf("Initialized %d routers", len(ctrlList)))
@@ -77,7 +86,12 @@ func Documentate() chioas.Definition {
}
for _, ctrl := range ctrlList {
documentatePaths, components := ctrl.Documentate()
documentated, ok := ctrl.(controller.DocumentateController)
if !ok {
continue
}
documentatePaths, components := documentated.Documentate()
if documentatePaths != nil {
for path, pathDoc := range *documentatePaths {