support multi-module (#4)

* add multimodule
* re-package modules
This commit is contained in:
Ilia Denisov
2026-02-22 08:57:19 +02:00
committed by GitHub
parent 9e36d7151e
commit 8f982278d2
132 changed files with 317 additions and 191 deletions
@@ -0,0 +1,75 @@
package router_test
import (
"encoding/json"
"net/http"
"galaxy/model/order"
"galaxy/model/rest"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/iliadenisov/galaxy/server/internal/router"
"github.com/iliadenisov/galaxy/server/internal/router/handler"
)
var (
commandNoErrorsStatus = http.StatusNoContent
commandDefaultActor = "Gorlum"
apiCommandMethod = "PUT"
apiCommandPath = "/api/v1/command"
apiOrderPath = "/api/v1/order"
validId1 = id()
validId2 = id()
invalidId = "fd091c69-5976-4775-b2f9-7ba77735afb"
)
func id() string {
return uuid.New().String()
}
type dummyExecutor struct {
CommandsExecuted int
}
func (e *dummyExecutor) ValidateOrder(actor string, cmd ...order.DecodableCommand) error {
e.CommandsExecuted = len(cmd)
return nil
}
func (e *dummyExecutor) Execute(command ...handler.Command) error {
e.CommandsExecuted = len(command)
return nil
}
func (e *dummyExecutor) GenerateGame(races []string) (rest.StateResponse, error) {
return rest.StateResponse{}, nil
}
func (e *dummyExecutor) GenerateTurn() (rest.StateResponse, error) {
return rest.StateResponse{}, nil
}
func (e *dummyExecutor) GameState() (rest.StateResponse, error) {
return rest.StateResponse{}, nil
}
func setupRouter() *gin.Engine {
return setupRouterExecutor(newExecutor())
}
func setupRouterExecutor(e handler.CommandExecutor) *gin.Engine {
return router.SetupRouter(e)
}
func newExecutor() handler.CommandExecutor {
return &dummyExecutor{}
}
func encodeCommand(cmd any) json.RawMessage {
v, err := json.Marshal(cmd)
if err != nil {
panic(err)
}
return v
}