Files
galaxy-game/internal/router/handler/init.go
T
Ilia Denisov d9c8de27e5 refactor: executors and routers
* refactor: executors and routers
2026-02-09 15:53:34 +03:00

30 lines
525 B
Go

package handler
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/iliadenisov/galaxy/internal/model/rest"
)
func InitHandler(c *gin.Context, executor CommandExecutor) {
var init rest.Init
if errorResponded(c, c.ShouldBindJSON(&init)) {
return
}
races := make([]string, len(init.Races))
for i := range init.Races {
races[i] = init.Races[i].Name
}
uuid, err := executor.GenerateGame(races)
if errorResponded(c, err) {
return
}
c.JSON(http.StatusCreated, rest.InitResponse{
UUID: uuid,
})
}