feat: command validation

This commit is contained in:
IliaDenisov
2026-02-10 18:31:53 +03:00
parent b5400bd61e
commit 6c8384ce7a
6 changed files with 178 additions and 30 deletions
+21 -7
View File
@@ -3,15 +3,15 @@ package rest
import "encoding/json"
type Command struct {
Actor string `json:"actor" binding:"required,notblank"`
Commands []json.RawMessage `json:"cmd" binding:"min=1"`
Actor string `json:"actor" binding:"required,notblank"`
Commands []json.RawMessage `json:"cmd" binding:"min=1"`
}
type CommandType string
const (
CommandTypeRaceQuit CommandType = "quit"
CommandTypeRaceVote CommandType = "vote"
CommandTypeRaceQuit CommandType = "raceQuit"
CommandTypeRaceVote CommandType = "raceVote"
CommandTypeRaceRelation CommandType = "declarePeace"
CommandTypeShipClassCreate CommandType = "shipClassCreate"
CommandTypeShipClassMerge CommandType = "shipClassMerge"
@@ -36,16 +36,30 @@ const (
)
type CommandMeta struct {
Type CommandType `json:"@type"`
Type CommandType `json:"@type" binding:"required,notblank"`
}
type CommandVote struct {
type CommandRaceQuit struct {
CommandMeta
}
type CommandRaceVote struct {
CommandMeta
Recipient string `json:"recipient" binding:"required,notblank"`
}
type CommandUpdateRelation struct {
type CommandRaceRelation struct {
CommandMeta
Opponent string `json:"recipient" binding:"required,notblank"`
Relation string `json:"relation" binding:"required,notblank"`
}
type CommandShipClassCreate struct {
CommandMeta
Name string `json:"name" binding:"required,notblank"`
Drive float64 `json:"drive" binding:"eq=0|gte=1"`
Armament int `json:"armament" binding:"ammoWeapons=Weapons"`
Weapons float64 `json:"weapons" binding:"ammoWeapons=Armament"`
Shields float64 `json:"shields" binding:"eq=0|gte=1"`
Cargo float64 `json:"cargo" binding:"eq=0|gte=1"`
}