refactor: executors and routers

* refactor: executors and routers
This commit is contained in:
Ilia Denisov
2026-02-09 15:53:34 +03:00
committed by GitHub
parent e48a0c8b96
commit d9c8de27e5
38 changed files with 508 additions and 838 deletions
+6 -13
View File
@@ -8,7 +8,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/go-playground/validator/v10"
"github.com/iliadenisov/galaxy/internal/controller"
"github.com/iliadenisov/galaxy/internal/router/handler"
)
@@ -16,12 +15,6 @@ const (
ISO8601 = "2006-01-02 15:04:05.0 -07:00"
)
func initConfig() func(*controller.Param) {
return func(p *controller.Param) {
p.StoragePath = os.Getenv("STORAGE_PATH")
}
}
type Router struct {
r *gin.Engine
executor handler.CommandExecutor
@@ -32,14 +25,14 @@ func (r Router) Run() error {
}
func NewRouter() Router {
return NewRouterExecutor(handler.ExecuteCommand)
return NewRouterExecutor(handler.NewDefaultExecutor())
}
func NewRouterExecutor(executor handler.CommandExecutor) Router {
return Router{r: setupRouter(initConfig(), executor)}
return Router{r: setupRouter(executor)}
}
func setupRouter(config controller.Configurer, executor handler.CommandExecutor) *gin.Engine {
func setupRouter(executor handler.CommandExecutor) *gin.Engine {
gin.SetMode(gin.ReleaseMode)
r := gin.New()
@@ -55,9 +48,9 @@ func setupRouter(config controller.Configurer, executor handler.CommandExecutor)
groupV1 := r.Group("/api/v1")
groupV1.GET("/status", func(ctx *gin.Context) { handler.StatusHandler(ctx, config) })
groupV1.POST("/init", func(ctx *gin.Context) { handler.InitHandler(ctx, config) })
groupV1.PUT("/command", LimitMiddleware(1), func(ctx *gin.Context) { handler.CommandHandler(ctx, config, executor) })
groupV1.GET("/status", func(ctx *gin.Context) { handler.StatusHandler(ctx, executor) })
groupV1.POST("/init", func(ctx *gin.Context) { handler.InitHandler(ctx, executor) })
groupV1.PUT("/command", LimitMiddleware(1), func(ctx *gin.Context) { handler.CommandHandler(ctx, executor) })
return r
}