feat: command validation
This commit is contained in:
@@ -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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user