feat: generic version of MinGreaterEqualError/MaxLessEqualError (#56)
All checks were successful
ci/woodpecker/push/govulncheck Pipeline was successful
ci/woodpecker/push/test Pipeline was successful

Reviewed-on: #56
This commit is contained in:
Dawid Wysokiński 2024-06-10 13:52:59 +00:00
parent 51a6270812
commit 86d78c0f0c
43 changed files with 296 additions and 265 deletions

View File

@ -26,7 +26,7 @@ func NewBaseEnnoblement(
points int,
createdAt time.Time,
) (BaseEnnoblement, error) {
if err := validateIntInRange(villageID, 1, math.MaxInt); err != nil {
if err := validateInRange(villageID, 1, math.MaxInt); err != nil {
return BaseEnnoblement{}, ValidationError{
Model: baseEnnoblementModelName,
Field: "villageID",
@ -34,7 +34,7 @@ func NewBaseEnnoblement(
}
}
if err := validateIntInRange(newOwnerID, 0, math.MaxInt); err != nil {
if err := validateInRange(newOwnerID, 0, math.MaxInt); err != nil {
return BaseEnnoblement{}, ValidationError{
Model: baseEnnoblementModelName,
Field: "newOwnerID",
@ -42,7 +42,7 @@ func NewBaseEnnoblement(
}
}
if err := validateIntInRange(newTribeID, 0, math.MaxInt); err != nil {
if err := validateInRange(newTribeID, 0, math.MaxInt); err != nil {
return BaseEnnoblement{}, ValidationError{
Model: baseEnnoblementModelName,
Field: "newTribeID",
@ -50,7 +50,7 @@ func NewBaseEnnoblement(
}
}
if err := validateIntInRange(oldOwnerID, 0, math.MaxInt); err != nil {
if err := validateInRange(oldOwnerID, 0, math.MaxInt); err != nil {
return BaseEnnoblement{}, ValidationError{
Model: baseEnnoblementModelName,
Field: "oldOwnerID",
@ -58,7 +58,7 @@ func NewBaseEnnoblement(
}
}
if err := validateIntInRange(oldTribeID, 0, math.MaxInt); err != nil {
if err := validateInRange(oldTribeID, 0, math.MaxInt); err != nil {
return BaseEnnoblement{}, ValidationError{
Model: baseEnnoblementModelName,
Field: "oldTribeID",
@ -66,7 +66,7 @@ func NewBaseEnnoblement(
}
}
if err := validateIntInRange(points, 0, math.MaxInt); err != nil {
if err := validateInRange(points, 0, math.MaxInt); err != nil {
return BaseEnnoblement{}, ValidationError{
Model: baseEnnoblementModelName,
Field: "points",

View File

@ -56,7 +56,7 @@ func TestNewBaseEnnoblement(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseEnnoblement",
Field: "villageID",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -76,7 +76,7 @@ func TestNewBaseEnnoblement(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseEnnoblement",
Field: "newOwnerID",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -96,7 +96,7 @@ func TestNewBaseEnnoblement(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseEnnoblement",
Field: "newTribeID",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -116,7 +116,7 @@ func TestNewBaseEnnoblement(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseEnnoblement",
Field: "oldOwnerID",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -136,7 +136,7 @@ func TestNewBaseEnnoblement(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseEnnoblement",
Field: "oldTribeID",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -156,7 +156,7 @@ func TestNewBaseEnnoblement(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseEnnoblement",
Field: "points",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},

View File

@ -28,7 +28,7 @@ func NewBasePlayer(
od OpponentsDefeated,
profileURL *url.URL,
) (BasePlayer, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return BasePlayer{}, ValidationError{
Model: basePlayerModelName,
Field: "id",
@ -44,7 +44,7 @@ func NewBasePlayer(
}
}
if err := validateIntInRange(numVillages, 0, math.MaxInt); err != nil {
if err := validateInRange(numVillages, 0, math.MaxInt); err != nil {
return BasePlayer{}, ValidationError{
Model: basePlayerModelName,
Field: "numVillages",
@ -52,7 +52,7 @@ func NewBasePlayer(
}
}
if err := validateIntInRange(points, 0, math.MaxInt); err != nil {
if err := validateInRange(points, 0, math.MaxInt); err != nil {
return BasePlayer{}, ValidationError{
Model: basePlayerModelName,
Field: "points",
@ -60,7 +60,7 @@ func NewBasePlayer(
}
}
if err := validateIntInRange(rank, 0, math.MaxInt); err != nil {
if err := validateInRange(rank, 0, math.MaxInt); err != nil {
return BasePlayer{}, ValidationError{
Model: basePlayerModelName,
Field: "rank",
@ -68,7 +68,7 @@ func NewBasePlayer(
}
}
if err := validateIntInRange(tribeID, 0, math.MaxInt); err != nil {
if err := validateInRange(tribeID, 0, math.MaxInt); err != nil {
return BasePlayer{}, ValidationError{
Model: basePlayerModelName,
Field: "tribeID",

View File

@ -60,7 +60,7 @@ func TestNewBasePlayer(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BasePlayer",
Field: "id",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -125,7 +125,7 @@ func TestNewBasePlayer(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BasePlayer",
Field: "numVillages",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -146,7 +146,7 @@ func TestNewBasePlayer(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BasePlayer",
Field: "points",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -167,7 +167,7 @@ func TestNewBasePlayer(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BasePlayer",
Field: "rank",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -188,7 +188,7 @@ func TestNewBasePlayer(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BasePlayer",
Field: "tribeID",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},

View File

@ -33,7 +33,7 @@ func NewBaseTribe(
od OpponentsDefeated,
profileURL *url.URL,
) (BaseTribe, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return BaseTribe{}, ValidationError{
Model: baseTribeModelName,
Field: "id",
@ -60,7 +60,7 @@ func NewBaseTribe(
}
}
if err := validateIntInRange(numMembers, 0, math.MaxInt); err != nil {
if err := validateInRange(numMembers, 0, math.MaxInt); err != nil {
return BaseTribe{}, ValidationError{
Model: baseTribeModelName,
Field: "numMembers",
@ -68,7 +68,7 @@ func NewBaseTribe(
}
}
if err := validateIntInRange(numVillages, 0, math.MaxInt); err != nil {
if err := validateInRange(numVillages, 0, math.MaxInt); err != nil {
return BaseTribe{}, ValidationError{
Model: baseTribeModelName,
Field: "numVillages",
@ -76,7 +76,7 @@ func NewBaseTribe(
}
}
if err := validateIntInRange(points, 0, math.MaxInt); err != nil {
if err := validateInRange(points, 0, math.MaxInt); err != nil {
return BaseTribe{}, ValidationError{
Model: baseTribeModelName,
Field: "points",
@ -84,7 +84,7 @@ func NewBaseTribe(
}
}
if err := validateIntInRange(allPoints, 0, math.MaxInt); err != nil {
if err := validateInRange(allPoints, 0, math.MaxInt); err != nil {
return BaseTribe{}, ValidationError{
Model: baseTribeModelName,
Field: "allPoints",
@ -92,7 +92,7 @@ func NewBaseTribe(
}
}
if err := validateIntInRange(rank, 0, math.MaxInt); err != nil {
if err := validateInRange(rank, 0, math.MaxInt); err != nil {
return BaseTribe{}, ValidationError{
Model: baseTribeModelName,
Field: "rank",

View File

@ -81,7 +81,7 @@ func TestNewBaseTribe(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseTribe",
Field: "id",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -200,7 +200,7 @@ func TestNewBaseTribe(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseTribe",
Field: "numMembers",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -223,7 +223,7 @@ func TestNewBaseTribe(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseTribe",
Field: "numVillages",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -246,7 +246,7 @@ func TestNewBaseTribe(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseTribe",
Field: "points",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -269,7 +269,7 @@ func TestNewBaseTribe(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseTribe",
Field: "allPoints",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -292,7 +292,7 @@ func TestNewBaseTribe(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseTribe",
Field: "rank",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},

View File

@ -29,7 +29,7 @@ func NewBaseVillage(
playerID int,
profileURL *url.URL,
) (BaseVillage, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return BaseVillage{}, ValidationError{
Model: baseVillageModelName,
Field: "id",
@ -45,7 +45,7 @@ func NewBaseVillage(
}
}
if err := validateIntInRange(points, 0, math.MaxInt); err != nil {
if err := validateInRange(points, 0, math.MaxInt); err != nil {
return BaseVillage{}, ValidationError{
Model: baseVillageModelName,
Field: "points",
@ -53,7 +53,7 @@ func NewBaseVillage(
}
}
if err := validateIntInRange(x, 0, math.MaxInt); err != nil {
if err := validateInRange(x, 0, math.MaxInt); err != nil {
return BaseVillage{}, ValidationError{
Model: baseVillageModelName,
Field: "x",
@ -61,7 +61,7 @@ func NewBaseVillage(
}
}
if err := validateIntInRange(y, 0, math.MaxInt); err != nil {
if err := validateInRange(y, 0, math.MaxInt); err != nil {
return BaseVillage{}, ValidationError{
Model: baseVillageModelName,
Field: "y",
@ -77,7 +77,7 @@ func NewBaseVillage(
}
}
if err := validateIntInRange(bonus, 0, math.MaxInt); err != nil {
if err := validateInRange(bonus, 0, math.MaxInt); err != nil {
return BaseVillage{}, ValidationError{
Model: baseVillageModelName,
Field: "bonus",
@ -85,7 +85,7 @@ func NewBaseVillage(
}
}
if err := validateIntInRange(playerID, 0, math.MaxInt); err != nil {
if err := validateInRange(playerID, 0, math.MaxInt); err != nil {
return BaseVillage{}, ValidationError{
Model: baseVillageModelName,
Field: "playerID",

View File

@ -63,7 +63,7 @@ func TestNewBaseVillage(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseVillage",
Field: "id",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -131,7 +131,7 @@ func TestNewBaseVillage(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseVillage",
Field: "points",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -153,7 +153,7 @@ func TestNewBaseVillage(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseVillage",
Field: "x",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -175,7 +175,7 @@ func TestNewBaseVillage(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseVillage",
Field: "y",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -243,7 +243,7 @@ func TestNewBaseVillage(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseVillage",
Field: "bonus",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -265,7 +265,7 @@ func TestNewBaseVillage(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "BaseVillage",
Field: "playerID",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},

View File

@ -37,7 +37,7 @@ func UnmarshalEnnoblementFromDatabase(
points int,
createdAt time.Time,
) (Ennoblement, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return Ennoblement{}, ValidationError{
Model: ennoblementModelName,
Field: "id",
@ -265,7 +265,7 @@ type EnnoblementCursor struct {
const ennoblementCursorModelName = "EnnoblementCursor"
func NewEnnoblementCursor(id int, serverKey string, createdAt time.Time) (EnnoblementCursor, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return EnnoblementCursor{}, ValidationError{
Model: ennoblementCursorModelName,
Field: "id",
@ -405,7 +405,7 @@ func (params *ListEnnoblementsParams) VillageIDs() []int {
func (params *ListEnnoblementsParams) SetVillageIDs(villageIDs []int) error {
for i, id := range villageIDs {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return SliceElementValidationError{
Model: listEnnoblementsParamsModelName,
Field: "villageIDs",
@ -426,7 +426,7 @@ func (params *ListEnnoblementsParams) PlayerIDs() []int {
func (params *ListEnnoblementsParams) SetPlayerIDs(playerIDs []int) error {
for i, id := range playerIDs {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return SliceElementValidationError{
Model: listEnnoblementsParamsModelName,
Field: "playerIDs",
@ -447,7 +447,7 @@ func (params *ListEnnoblementsParams) TribeIDs() []int {
func (params *ListEnnoblementsParams) SetTribeIDs(tribeIDs []int) error {
for i, id := range tribeIDs {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return SliceElementValidationError{
Model: listEnnoblementsParamsModelName,
Field: "tribeIDs",
@ -579,7 +579,7 @@ func (params *ListEnnoblementsParams) Limit() int {
}
func (params *ListEnnoblementsParams) SetLimit(limit int) error {
if err := validateIntInRange(limit, 1, EnnoblementListMaxLimit); err != nil {
if err := validateInRange(limit, 1, EnnoblementListMaxLimit); err != nil {
return ValidationError{
Model: listEnnoblementsParamsModelName,
Field: "limit",

View File

@ -141,7 +141,7 @@ func TestNewEnnoblementCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "EnnoblementCursor",
Field: "id",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -276,7 +276,7 @@ func TestListEnnoblementsParams_SetVillageIDs(t *testing.T) {
Model: "ListEnnoblementsParams",
Field: "villageIDs",
Index: 3,
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -336,7 +336,7 @@ func TestListEnnoblementsParams_SetPlayerIDs(t *testing.T) {
Model: "ListEnnoblementsParams",
Field: "playerIDs",
Index: 3,
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -396,7 +396,7 @@ func TestListEnnoblementsParams_SetTribeIDs(t *testing.T) {
Model: "ListEnnoblementsParams",
Field: "tribeIDs",
Index: 3,
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -957,7 +957,7 @@ func TestListEnnoblementsParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListEnnoblementsParams",
Field: "limit",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -971,7 +971,7 @@ func TestListEnnoblementsParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListEnnoblementsParams",
Field: "limit",
Err: domain.MaxLessEqualError{
Err: domain.MaxLessEqualError[int]{
Max: domain.EnnoblementListMaxLimit,
Current: domain.EnnoblementListMaxLimit + 1,
},

View File

@ -149,7 +149,7 @@ func NewTribesSyncedEventPayload(
}
}
if err := validateIntInRange(numTribes, 0, math.MaxInt); err != nil {
if err := validateInRange(numTribes, 0, math.MaxInt); err != nil {
return TribesSyncedEventPayload{}, ValidationError{
Model: tribesSyncedEventPayloadModelName,
Field: "numTribes",
@ -157,7 +157,7 @@ func NewTribesSyncedEventPayload(
}
}
if err := validateIntInRange(numActiveTribes, 0, math.MaxInt); err != nil {
if err := validateInRange(numActiveTribes, 0, math.MaxInt); err != nil {
return TribesSyncedEventPayload{}, ValidationError{
Model: tribesSyncedEventPayloadModelName,
Field: "numActiveTribes",
@ -239,7 +239,7 @@ func NewPlayersSyncedEventPayload(
}
}
if err := validateIntInRange(numPlayers, 0, math.MaxInt); err != nil {
if err := validateInRange(numPlayers, 0, math.MaxInt); err != nil {
return PlayersSyncedEventPayload{}, ValidationError{
Model: playersSyncedEventPayloadModelName,
Field: "numPlayers",
@ -247,7 +247,7 @@ func NewPlayersSyncedEventPayload(
}
}
if err := validateIntInRange(numActivePlayers, 0, math.MaxInt); err != nil {
if err := validateInRange(numActivePlayers, 0, math.MaxInt); err != nil {
return PlayersSyncedEventPayload{}, ValidationError{
Model: playersSyncedEventPayloadModelName,
Field: "numActivePlayers",
@ -333,7 +333,7 @@ func NewVillagesSyncedEventPayload(
}
}
if err := validateIntInRange(numVillages, 0, math.MaxInt); err != nil {
if err := validateInRange(numVillages, 0, math.MaxInt); err != nil {
return VillagesSyncedEventPayload{}, ValidationError{
Model: villagesSyncedEventPayloadModelName,
Field: "numVillages",
@ -341,7 +341,7 @@ func NewVillagesSyncedEventPayload(
}
}
if err := validateIntInRange(numPlayerVillages, 0, math.MaxInt); err != nil {
if err := validateInRange(numPlayerVillages, 0, math.MaxInt); err != nil {
return VillagesSyncedEventPayload{}, ValidationError{
Model: villagesSyncedEventPayloadModelName,
Field: "numPlayerVillages",
@ -349,7 +349,7 @@ func NewVillagesSyncedEventPayload(
}
}
if err := validateIntInRange(numBarbarianVillages, 0, math.MaxInt); err != nil {
if err := validateInRange(numBarbarianVillages, 0, math.MaxInt); err != nil {
return VillagesSyncedEventPayload{}, ValidationError{
Model: villagesSyncedEventPayloadModelName,
Field: "numBarbarianVillages",
@ -357,7 +357,7 @@ func NewVillagesSyncedEventPayload(
}
}
if err := validateIntInRange(numBonusVillages, 0, math.MaxInt); err != nil {
if err := validateInRange(numBonusVillages, 0, math.MaxInt); err != nil {
return VillagesSyncedEventPayload{}, ValidationError{
Model: villagesSyncedEventPayloadModelName,
Field: "numBonusVillages",

View File

@ -25,7 +25,7 @@ func NewOpponentsDefeated(
rankTotal int,
scoreTotal int,
) (OpponentsDefeated, error) {
if err := validateIntInRange(rankAtt, 0, math.MaxInt); err != nil {
if err := validateInRange(rankAtt, 0, math.MaxInt); err != nil {
return OpponentsDefeated{}, ValidationError{
Model: opponentsDefeatedModelName,
Field: "rankAtt",
@ -33,7 +33,7 @@ func NewOpponentsDefeated(
}
}
if err := validateIntInRange(scoreAtt, 0, math.MaxInt); err != nil {
if err := validateInRange(scoreAtt, 0, math.MaxInt); err != nil {
return OpponentsDefeated{}, ValidationError{
Model: opponentsDefeatedModelName,
Field: "scoreAtt",
@ -41,7 +41,7 @@ func NewOpponentsDefeated(
}
}
if err := validateIntInRange(rankDef, 0, math.MaxInt); err != nil {
if err := validateInRange(rankDef, 0, math.MaxInt); err != nil {
return OpponentsDefeated{}, ValidationError{
Model: opponentsDefeatedModelName,
Field: "rankDef",
@ -49,7 +49,7 @@ func NewOpponentsDefeated(
}
}
if err := validateIntInRange(scoreDef, 0, math.MaxInt); err != nil {
if err := validateInRange(scoreDef, 0, math.MaxInt); err != nil {
return OpponentsDefeated{}, ValidationError{
Model: opponentsDefeatedModelName,
Field: "scoreDef",
@ -57,7 +57,7 @@ func NewOpponentsDefeated(
}
}
if err := validateIntInRange(rankSup, 0, math.MaxInt); err != nil {
if err := validateInRange(rankSup, 0, math.MaxInt); err != nil {
return OpponentsDefeated{}, ValidationError{
Model: opponentsDefeatedModelName,
Field: "rankSup",
@ -65,7 +65,7 @@ func NewOpponentsDefeated(
}
}
if err := validateIntInRange(scoreSup, 0, math.MaxInt); err != nil {
if err := validateInRange(scoreSup, 0, math.MaxInt); err != nil {
return OpponentsDefeated{}, ValidationError{
Model: opponentsDefeatedModelName,
Field: "scoreSup",
@ -73,7 +73,7 @@ func NewOpponentsDefeated(
}
}
if err := validateIntInRange(rankTotal, 0, math.MaxInt); err != nil {
if err := validateInRange(rankTotal, 0, math.MaxInt); err != nil {
return OpponentsDefeated{}, ValidationError{
Model: opponentsDefeatedModelName,
Field: "rankTotal",
@ -81,7 +81,7 @@ func NewOpponentsDefeated(
}
}
if err := validateIntInRange(scoreTotal, 0, math.MaxInt); err != nil {
if err := validateInRange(scoreTotal, 0, math.MaxInt); err != nil {
return OpponentsDefeated{}, ValidationError{
Model: opponentsDefeatedModelName,
Field: "scoreTotal",

View File

@ -58,7 +58,7 @@ func TestNewOpponentsDefeated(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "OpponentsDefeated",
Field: "rankAtt",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -79,7 +79,7 @@ func TestNewOpponentsDefeated(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "OpponentsDefeated",
Field: "scoreAtt",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -100,7 +100,7 @@ func TestNewOpponentsDefeated(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "OpponentsDefeated",
Field: "rankDef",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -121,7 +121,7 @@ func TestNewOpponentsDefeated(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "OpponentsDefeated",
Field: "scoreDef",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -142,7 +142,7 @@ func TestNewOpponentsDefeated(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "OpponentsDefeated",
Field: "rankSup",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -163,7 +163,7 @@ func TestNewOpponentsDefeated(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "OpponentsDefeated",
Field: "scoreSup",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -184,7 +184,7 @@ func TestNewOpponentsDefeated(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "OpponentsDefeated",
Field: "rankTotal",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -205,7 +205,7 @@ func TestNewOpponentsDefeated(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "OpponentsDefeated",
Field: "scoreTotal",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},

View File

@ -61,7 +61,7 @@ func UnmarshalPlayerFromDatabase(
createdAt time.Time,
deletedAt time.Time,
) (Player, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return Player{}, ValidationError{
Model: playerModelName,
Field: "id",
@ -327,7 +327,7 @@ const playerMetaModelName = "PlayerMeta"
// It should be used only for unmarshalling from the database!
// You can't use UnmarshalPlayerMetaFromDatabase as constructor - It may put domain into the invalid state!
func UnmarshalPlayerMetaFromDatabase(id int, name string, rawProfileURL string) (PlayerMeta, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return PlayerMeta{}, ValidationError{
Model: playerMetaModelName,
Field: "id",
@ -633,7 +633,7 @@ func NewPlayerCursor(
mostPoints int,
deletedAt time.Time,
) (PlayerCursor, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return PlayerCursor{}, ValidationError{
Model: playerCursorModelName,
Field: "id",
@ -649,7 +649,7 @@ func NewPlayerCursor(
}
}
if err := validateIntInRange(odScoreAtt, 0, math.MaxInt); err != nil {
if err := validateInRange(odScoreAtt, 0, math.MaxInt); err != nil {
return PlayerCursor{}, ValidationError{
Model: playerCursorModelName,
Field: "odScoreAtt",
@ -657,7 +657,7 @@ func NewPlayerCursor(
}
}
if err := validateIntInRange(odScoreDef, 0, math.MaxInt); err != nil {
if err := validateInRange(odScoreDef, 0, math.MaxInt); err != nil {
return PlayerCursor{}, ValidationError{
Model: playerCursorModelName,
Field: "odScoreDef",
@ -665,7 +665,7 @@ func NewPlayerCursor(
}
}
if err := validateIntInRange(odScoreSup, 0, math.MaxInt); err != nil {
if err := validateInRange(odScoreSup, 0, math.MaxInt); err != nil {
return PlayerCursor{}, ValidationError{
Model: playerCursorModelName,
Field: "odScoreSup",
@ -673,7 +673,7 @@ func NewPlayerCursor(
}
}
if err := validateIntInRange(odScoreTotal, 0, math.MaxInt); err != nil {
if err := validateInRange(odScoreTotal, 0, math.MaxInt); err != nil {
return PlayerCursor{}, ValidationError{
Model: playerCursorModelName,
Field: "odScoreTotal",
@ -681,7 +681,7 @@ func NewPlayerCursor(
}
}
if err := validateIntInRange(points, 0, math.MaxInt); err != nil {
if err := validateInRange(points, 0, math.MaxInt); err != nil {
return PlayerCursor{}, ValidationError{
Model: playerCursorModelName,
Field: "points",
@ -689,7 +689,7 @@ func NewPlayerCursor(
}
}
if err := validateIntInRange(mostPoints, 0, math.MaxInt); err != nil {
if err := validateInRange(mostPoints, 0, math.MaxInt); err != nil {
return PlayerCursor{}, ValidationError{
Model: playerCursorModelName,
Field: "mostPoints",
@ -871,7 +871,7 @@ func (params *ListPlayersParams) IDs() []int {
func (params *ListPlayersParams) SetIDs(ids []int) error {
for i, id := range ids {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return SliceElementValidationError{
Model: listPlayersParamsModelName,
Field: "ids",
@ -968,7 +968,7 @@ func (params *ListPlayersParams) TribeIDs() []int {
func (params *ListPlayersParams) SetTribeIDs(tribeIDs []int) error {
for i, id := range tribeIDs {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return SliceElementValidationError{
Model: listPlayersParamsModelName,
Field: "tribeIDs",
@ -1091,7 +1091,7 @@ func (params *ListPlayersParams) Limit() int {
}
func (params *ListPlayersParams) SetLimit(limit int) error {
if err := validateIntInRange(limit, 1, PlayerListMaxLimit); err != nil {
if err := validateInRange(limit, 1, PlayerListMaxLimit); err != nil {
return ValidationError{
Model: listPlayersParamsModelName,
Field: "limit",

View File

@ -39,7 +39,7 @@ func UnmarshalPlayerSnapshotFromDatabase(
date time.Time,
createdAt time.Time,
) (PlayerSnapshot, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return PlayerSnapshot{}, ValidationError{
Model: playerSnapshotModelName,
Field: "id",
@ -47,7 +47,7 @@ func UnmarshalPlayerSnapshotFromDatabase(
}
}
if err := validateIntInRange(playerID, 1, math.MaxInt); err != nil {
if err := validateInRange(playerID, 1, math.MaxInt); err != nil {
return PlayerSnapshot{}, ValidationError{
Model: playerSnapshotModelName,
Field: "playerID",
@ -275,7 +275,7 @@ type PlayerSnapshotCursor struct {
const playerSnapshotCursorModelName = "PlayerSnapshotCursor"
func NewPlayerSnapshotCursor(id int, serverKey string, date time.Time) (PlayerSnapshotCursor, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return PlayerSnapshotCursor{}, ValidationError{
Model: playerSnapshotCursorModelName,
Field: "id",
@ -411,7 +411,7 @@ func (params *ListPlayerSnapshotsParams) PlayerIDs() []int {
func (params *ListPlayerSnapshotsParams) SetPlayerIDs(playerIDs []int) error {
for i, id := range playerIDs {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return SliceElementValidationError{
Model: listPlayerSnapshotsParamsModelName,
Field: "playerIDs",
@ -529,7 +529,7 @@ func (params *ListPlayerSnapshotsParams) Limit() int {
}
func (params *ListPlayerSnapshotsParams) SetLimit(limit int) error {
if err := validateIntInRange(limit, 1, PlayerSnapshotListMaxLimit); err != nil {
if err := validateInRange(limit, 1, PlayerSnapshotListMaxLimit); err != nil {
return ValidationError{
Model: listPlayerSnapshotsParamsModelName,
Field: "limit",

View File

@ -147,7 +147,7 @@ func TestNewPlayerSnapshotCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "PlayerSnapshotCursor",
Field: "id",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -282,7 +282,7 @@ func TestListPlayerSnapshotsParams_SetPlayerIDs(t *testing.T) {
Model: "ListPlayerSnapshotsParams",
Field: "playerIDs",
Index: 3,
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -840,7 +840,7 @@ func TestListPlayerSnapshotsParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListPlayerSnapshotsParams",
Field: "limit",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -854,7 +854,7 @@ func TestListPlayerSnapshotsParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListPlayerSnapshotsParams",
Field: "limit",
Err: domain.MaxLessEqualError{
Err: domain.MaxLessEqualError[int]{
Max: domain.PlayerSnapshotListMaxLimit,
Current: domain.PlayerSnapshotListMaxLimit + 1,
},

View File

@ -383,7 +383,7 @@ func TestNewPlayerCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "PlayerCursor",
Field: "id",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -405,7 +405,7 @@ func TestNewPlayerCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "PlayerCursor",
Field: "odScoreAtt",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -427,7 +427,7 @@ func TestNewPlayerCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "PlayerCursor",
Field: "odScoreDef",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -449,7 +449,7 @@ func TestNewPlayerCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "PlayerCursor",
Field: "odScoreSup",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -471,7 +471,7 @@ func TestNewPlayerCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "PlayerCursor",
Field: "odScoreTotal",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -493,7 +493,7 @@ func TestNewPlayerCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "PlayerCursor",
Field: "points",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -515,7 +515,7 @@ func TestNewPlayerCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "PlayerCursor",
Field: "mostPoints",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -613,7 +613,7 @@ func TestListPlayersParams_SetIDs(t *testing.T) {
Model: "ListPlayersParams",
Field: "ids",
Index: 3,
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -884,7 +884,7 @@ func TestListPlayersParams_SetTribeIDs(t *testing.T) {
Model: "ListPlayersParams",
Field: "tribeIDs",
Index: 3,
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -1529,7 +1529,7 @@ func TestListPlayersParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListPlayersParams",
Field: "limit",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -1543,7 +1543,7 @@ func TestListPlayersParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListPlayersParams",
Field: "limit",
Err: domain.MaxLessEqualError{
Err: domain.MaxLessEqualError[int]{
Max: domain.PlayerListMaxLimit,
Current: domain.PlayerListMaxLimit + 1,
},

View File

@ -466,7 +466,7 @@ func (params *UpdateServerParams) NumTribes() NullInt {
func (params *UpdateServerParams) SetNumTribes(num NullInt) error {
if num.Valid {
if err := validateIntInRange(num.V, 0, math.MaxInt); err != nil {
if err := validateInRange(num.V, 0, math.MaxInt); err != nil {
return ValidationError{
Model: updateServerParamsModelName,
Field: "numTribes",
@ -486,7 +486,7 @@ func (params *UpdateServerParams) NumActiveTribes() NullInt {
func (params *UpdateServerParams) SetNumActiveTribes(num NullInt) error {
if num.Valid {
if err := validateIntInRange(num.V, 0, math.MaxInt); err != nil {
if err := validateInRange(num.V, 0, math.MaxInt); err != nil {
return ValidationError{
Model: updateServerParamsModelName,
Field: "numActiveTribes",
@ -506,7 +506,7 @@ func (params *UpdateServerParams) NumInactiveTribes() NullInt {
func (params *UpdateServerParams) SetNumInactiveTribes(num NullInt) error {
if num.Valid {
if err := validateIntInRange(num.V, 0, math.MaxInt); err != nil {
if err := validateInRange(num.V, 0, math.MaxInt); err != nil {
return ValidationError{
Model: updateServerParamsModelName,
Field: "numInactiveTribes",
@ -535,7 +535,7 @@ func (params *UpdateServerParams) NumPlayers() NullInt {
func (params *UpdateServerParams) SetNumPlayers(num NullInt) error {
if num.Valid {
if err := validateIntInRange(num.V, 0, math.MaxInt); err != nil {
if err := validateInRange(num.V, 0, math.MaxInt); err != nil {
return ValidationError{
Model: updateServerParamsModelName,
Field: "numPlayers",
@ -555,7 +555,7 @@ func (params *UpdateServerParams) NumActivePlayers() NullInt {
func (params *UpdateServerParams) SetNumActivePlayers(num NullInt) error {
if num.Valid {
if err := validateIntInRange(num.V, 0, math.MaxInt); err != nil {
if err := validateInRange(num.V, 0, math.MaxInt); err != nil {
return ValidationError{
Model: updateServerParamsModelName,
Field: "numActivePlayers",
@ -575,7 +575,7 @@ func (params *UpdateServerParams) NumInactivePlayers() NullInt {
func (params *UpdateServerParams) SetNumInactivePlayers(num NullInt) error {
if num.Valid {
if err := validateIntInRange(num.V, 0, math.MaxInt); err != nil {
if err := validateInRange(num.V, 0, math.MaxInt); err != nil {
return ValidationError{
Model: updateServerParamsModelName,
Field: "numInactivePlayers",
@ -604,7 +604,7 @@ func (params *UpdateServerParams) NumVillages() NullInt {
func (params *UpdateServerParams) SetNumVillages(numVillages NullInt) error {
if numVillages.Valid {
if err := validateIntInRange(numVillages.V, 0, math.MaxInt); err != nil {
if err := validateInRange(numVillages.V, 0, math.MaxInt); err != nil {
return ValidationError{
Model: updateServerParamsModelName,
Field: "numVillages",
@ -624,7 +624,7 @@ func (params *UpdateServerParams) NumPlayerVillages() NullInt {
func (params *UpdateServerParams) SetNumPlayerVillages(numPlayerVillages NullInt) error {
if numPlayerVillages.Valid {
if err := validateIntInRange(numPlayerVillages.V, 0, math.MaxInt); err != nil {
if err := validateInRange(numPlayerVillages.V, 0, math.MaxInt); err != nil {
return ValidationError{
Model: updateServerParamsModelName,
Field: "numPlayerVillages",
@ -644,7 +644,7 @@ func (params *UpdateServerParams) NumBarbarianVillages() NullInt {
func (params *UpdateServerParams) SetNumBarbarianVillages(numBarbarianVillages NullInt) error {
if numBarbarianVillages.Valid {
if err := validateIntInRange(numBarbarianVillages.V, 0, math.MaxInt); err != nil {
if err := validateInRange(numBarbarianVillages.V, 0, math.MaxInt); err != nil {
return ValidationError{
Model: updateServerParamsModelName,
Field: "numBarbarianVillages",
@ -664,7 +664,7 @@ func (params *UpdateServerParams) NumBonusVillages() NullInt {
func (params *UpdateServerParams) SetNumBonusVillages(numBonusVillages NullInt) error {
if numBonusVillages.Valid {
if err := validateIntInRange(numBonusVillages.V, 0, math.MaxInt); err != nil {
if err := validateInRange(numBonusVillages.V, 0, math.MaxInt); err != nil {
return ValidationError{
Model: updateServerParamsModelName,
Field: "numBonusVillages",
@ -1006,7 +1006,7 @@ func (params *ListServersParams) Limit() int {
}
func (params *ListServersParams) SetLimit(limit int) error {
if err := validateIntInRange(limit, 1, ServerListMaxLimit); err != nil {
if err := validateInRange(limit, 1, ServerListMaxLimit); err != nil {
return ValidationError{
Model: listServersParamsModelName,
Field: "limit",

View File

@ -0,0 +1,31 @@
package domain
type ServerMap struct {
server Server
villagesCh <-chan VillageMetaWithRelations
scale float32
}
const serverMapModelName = "ServerMap"
func NewServerMap(server Server, villagesCh <-chan VillageMetaWithRelations) ServerMap {
return ServerMap{
server: server,
villagesCh: villagesCh,
scale: 1,
}
}
func (m *ServerMap) SetScale(scale float32) error {
if err := validateInRange(scale, 0, 1); err != nil {
return ValidationError{
Model: serverMapModelName,
Field: "scale",
Err: err,
}
}
m.scale = scale
return nil
}

View File

@ -45,7 +45,7 @@ func UnmarshalServerSnapshotFromDatabase(
date time.Time,
createdAt time.Time,
) (ServerSnapshot, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return ServerSnapshot{}, ValidationError{
Model: serverSnapshotModelName,
Field: "id",
@ -305,7 +305,7 @@ type ServerSnapshotCursor struct {
const serverSnapshotCursorModelName = "ServerSnapshotCursor"
func NewServerSnapshotCursor(id int, serverKey string, date time.Time) (ServerSnapshotCursor, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return ServerSnapshotCursor{}, ValidationError{
Model: serverSnapshotCursorModelName,
Field: "id",
@ -536,7 +536,7 @@ func (params *ListServerSnapshotsParams) Limit() int {
}
func (params *ListServerSnapshotsParams) SetLimit(limit int) error {
if err := validateIntInRange(limit, 1, ServerSnapshotListMaxLimit); err != nil {
if err := validateInRange(limit, 1, ServerSnapshotListMaxLimit); err != nil {
return ValidationError{
Model: listServerSnapshotsParamsModelName,
Field: "limit",

View File

@ -136,7 +136,7 @@ func TestNewServerSnapshotCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ServerSnapshotCursor",
Field: "id",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -769,7 +769,7 @@ func TestListServerSnapshotsParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListServerSnapshotsParams",
Field: "limit",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -783,7 +783,7 @@ func TestListServerSnapshotsParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListServerSnapshotsParams",
Field: "limit",
Err: domain.MaxLessEqualError{
Err: domain.MaxLessEqualError[int]{
Max: domain.ServerSnapshotListMaxLimit,
Current: domain.ServerSnapshotListMaxLimit + 1,
},

View File

@ -201,7 +201,7 @@ func TestUpdateServerParams_SetNumTribes(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "UpdateServerParams",
Field: "numTribes",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -264,7 +264,7 @@ func TestUpdateServerParams_SetNumActiveTribes(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "UpdateServerParams",
Field: "numActiveTribes",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -327,7 +327,7 @@ func TestUpdateServerParams_SetNumInactiveTribes(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "UpdateServerParams",
Field: "numInactiveTribes",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -390,7 +390,7 @@ func TestUpdateServerParams_SetNumPlayers(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "UpdateServerParams",
Field: "numPlayers",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -453,7 +453,7 @@ func TestUpdateServerParams_SetNumActivePlayers(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "UpdateServerParams",
Field: "numActivePlayers",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -516,7 +516,7 @@ func TestUpdateServerParams_SetNumInactivePlayers(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "UpdateServerParams",
Field: "numInactivePlayers",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -579,7 +579,7 @@ func TestUpdateServerParams_SetNumVillages(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "UpdateServerParams",
Field: "numVillages",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -642,7 +642,7 @@ func TestUpdateServerParams_SetNumPlayerVillages(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "UpdateServerParams",
Field: "numPlayerVillages",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -705,7 +705,7 @@ func TestUpdateServerParams_SetNumBarbarianVillages(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "UpdateServerParams",
Field: "numBarbarianVillages",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -768,7 +768,7 @@ func TestUpdateServerParams_SetNumBonusVillages(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "UpdateServerParams",
Field: "numBonusVillages",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -1207,7 +1207,7 @@ func TestListServersParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListServersParams",
Field: "limit",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -1221,7 +1221,7 @@ func TestListServersParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListServersParams",
Field: "limit",
Err: domain.MaxLessEqualError{
Err: domain.MaxLessEqualError[int]{
Max: domain.ServerListMaxLimit,
Current: domain.ServerListMaxLimit + 1,
},

View File

@ -67,7 +67,7 @@ func UnmarshalTribeFromDatabase(
createdAt time.Time,
deletedAt time.Time,
) (Tribe, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return Tribe{}, ValidationError{
Model: tribeModelName,
Field: "id",
@ -296,7 +296,7 @@ const tribeMetaModelName = "TribeMeta"
// It should be used only for unmarshalling from the database!
// You can't use UnmarshalTribeMetaFromDatabase as constructor - It may put domain into the invalid state!
func UnmarshalTribeMetaFromDatabase(id int, name string, tag string, rawProfileURL string) (TribeMeta, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return TribeMeta{}, ValidationError{
Model: tribeMetaModelName,
Field: "id",
@ -555,7 +555,7 @@ func NewTribeCursor(
dominance float64,
deletedAt time.Time,
) (TribeCursor, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return TribeCursor{}, ValidationError{
Model: tribeCursorModelName,
Field: "id",
@ -571,7 +571,7 @@ func NewTribeCursor(
}
}
if err := validateIntInRange(odScoreAtt, 0, math.MaxInt); err != nil {
if err := validateInRange(odScoreAtt, 0, math.MaxInt); err != nil {
return TribeCursor{}, ValidationError{
Model: tribeCursorModelName,
Field: "odScoreAtt",
@ -579,7 +579,7 @@ func NewTribeCursor(
}
}
if err := validateIntInRange(odScoreDef, 0, math.MaxInt); err != nil {
if err := validateInRange(odScoreDef, 0, math.MaxInt); err != nil {
return TribeCursor{}, ValidationError{
Model: tribeCursorModelName,
Field: "odScoreDef",
@ -587,7 +587,7 @@ func NewTribeCursor(
}
}
if err := validateIntInRange(odScoreTotal, 0, math.MaxInt); err != nil {
if err := validateInRange(odScoreTotal, 0, math.MaxInt); err != nil {
return TribeCursor{}, ValidationError{
Model: tribeCursorModelName,
Field: "odScoreTotal",
@ -595,7 +595,7 @@ func NewTribeCursor(
}
}
if err := validateIntInRange(points, 0, math.MaxInt); err != nil {
if err := validateInRange(points, 0, math.MaxInt); err != nil {
return TribeCursor{}, ValidationError{
Model: tribeCursorModelName,
Field: "points",
@ -603,7 +603,7 @@ func NewTribeCursor(
}
}
if err := validateIntInRange(mostPoints, 0, math.MaxInt); err != nil {
if err := validateInRange(mostPoints, 0, math.MaxInt); err != nil {
return TribeCursor{}, ValidationError{
Model: tribeCursorModelName,
Field: "mostPoints",
@ -783,7 +783,7 @@ func (params *ListTribesParams) IDs() []int {
func (params *ListTribesParams) SetIDs(ids []int) error {
for i, id := range ids {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return SliceElementValidationError{
Model: listTribesParamsModelName,
Field: "ids",
@ -934,7 +934,7 @@ func (params *ListTribesParams) Limit() int {
}
func (params *ListTribesParams) SetLimit(limit int) error {
if err := validateIntInRange(limit, 1, TribeListMaxLimit); err != nil {
if err := validateInRange(limit, 1, TribeListMaxLimit); err != nil {
return ValidationError{
Model: listTribesParamsModelName,
Field: "limit",

View File

@ -31,7 +31,7 @@ func UnmarshalTribeChangeFromDatabase(
newTribeID int,
createdAt time.Time,
) (TribeChange, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return TribeChange{}, ValidationError{
Model: tribeChangeModelName,
Field: "id",
@ -156,7 +156,7 @@ func NewCreateTribeChangeParams(
}
}
if err := validateIntInRange(playerID, 1, math.MaxInt); err != nil {
if err := validateInRange(playerID, 1, math.MaxInt); err != nil {
return CreateTribeChangeParams{}, ValidationError{
Model: createTribeChangeParamsModelName,
Field: "playerID",
@ -164,7 +164,7 @@ func NewCreateTribeChangeParams(
}
}
if err := validateIntInRange(oldTribeID, 0, math.MaxInt); err != nil {
if err := validateInRange(oldTribeID, 0, math.MaxInt); err != nil {
return CreateTribeChangeParams{}, ValidationError{
Model: createTribeChangeParamsModelName,
Field: "oldTribeID",
@ -172,7 +172,7 @@ func NewCreateTribeChangeParams(
}
}
if err := validateIntInRange(newTribeID, 0, math.MaxInt); err != nil {
if err := validateInRange(newTribeID, 0, math.MaxInt); err != nil {
return CreateTribeChangeParams{}, ValidationError{
Model: createTribeChangeParamsModelName,
Field: "newTribeID",
@ -297,7 +297,7 @@ type TribeChangeCursor struct {
const tribeChangeCursorModelName = "TribeChangeCursor"
func NewTribeChangeCursor(id int, serverKey string, createdAt time.Time) (TribeChangeCursor, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return TribeChangeCursor{}, ValidationError{
Model: tribeChangeCursorModelName,
Field: "id",
@ -436,7 +436,7 @@ func (params *ListTribeChangesParams) PlayerIDs() []int {
func (params *ListTribeChangesParams) SetPlayerIDs(playerIDs []int) error {
for i, id := range playerIDs {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return SliceElementValidationError{
Model: listTribeChangesParamsModelName,
Field: "playerIDs",
@ -457,7 +457,7 @@ func (params *ListTribeChangesParams) TribeIDs() []int {
func (params *ListTribeChangesParams) SetTribeIDs(tribeIDs []int) error {
for i, id := range tribeIDs {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return SliceElementValidationError{
Model: listTribeChangesParamsModelName,
Field: "tribeIDs",
@ -542,7 +542,7 @@ func (params *ListTribeChangesParams) Limit() int {
}
func (params *ListTribeChangesParams) SetLimit(limit int) error {
if err := validateIntInRange(limit, 1, TribeChangeListMaxLimit); err != nil {
if err := validateInRange(limit, 1, TribeChangeListMaxLimit); err != nil {
return ValidationError{
Model: listTribeChangesParamsModelName,
Field: "limit",

View File

@ -53,7 +53,7 @@ func TestNewCreateTribeChangeParams(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "CreateTribeChangeParams",
Field: "playerID",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -70,7 +70,7 @@ func TestNewCreateTribeChangeParams(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "CreateTribeChangeParams",
Field: "oldTribeID",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -87,7 +87,7 @@ func TestNewCreateTribeChangeParams(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "CreateTribeChangeParams",
Field: "newTribeID",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -318,7 +318,7 @@ func TestNewTribeChangeCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "TribeChangeCursor",
Field: "id",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -453,7 +453,7 @@ func TestListTribeChangesParams_SetPlayerIDs(t *testing.T) {
Model: "ListTribeChangesParams",
Field: "playerIDs",
Index: 3,
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -513,7 +513,7 @@ func TestListTribeChangesParams_SetTribeIDs(t *testing.T) {
Model: "ListTribeChangesParams",
Field: "tribeIDs",
Index: 3,
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -1071,7 +1071,7 @@ func TestListTribeChangesParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListTribeChangesParams",
Field: "limit",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -1085,7 +1085,7 @@ func TestListTribeChangesParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListTribeChangesParams",
Field: "limit",
Err: domain.MaxLessEqualError{
Err: domain.MaxLessEqualError[int]{
Max: domain.TribeChangeListMaxLimit,
Current: domain.TribeChangeListMaxLimit + 1,
},

View File

@ -43,7 +43,7 @@ func UnmarshalTribeSnapshotFromDatabase(
date time.Time,
createdAt time.Time,
) (TribeSnapshot, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return TribeSnapshot{}, ValidationError{
Model: tribeSnapshotModelName,
Field: "id",
@ -51,7 +51,7 @@ func UnmarshalTribeSnapshotFromDatabase(
}
}
if err := validateIntInRange(tribeID, 1, math.MaxInt); err != nil {
if err := validateInRange(tribeID, 1, math.MaxInt); err != nil {
return TribeSnapshot{}, ValidationError{
Model: tribeSnapshotModelName,
Field: "tribeID",
@ -295,7 +295,7 @@ type TribeSnapshotCursor struct {
const tribeSnapshotCursorModelName = "TribeSnapshotCursor"
func NewTribeSnapshotCursor(id int, serverKey string, date time.Time) (TribeSnapshotCursor, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return TribeSnapshotCursor{}, ValidationError{
Model: tribeSnapshotCursorModelName,
Field: "id",
@ -430,7 +430,7 @@ func (params *ListTribeSnapshotsParams) TribeIDs() []int {
func (params *ListTribeSnapshotsParams) SetTribeIDs(tribeIDs []int) error {
for i, id := range tribeIDs {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return SliceElementValidationError{
Model: listTribeSnapshotsParamsModelName,
Field: "tribeIDs",
@ -548,7 +548,7 @@ func (params *ListTribeSnapshotsParams) Limit() int {
}
func (params *ListTribeSnapshotsParams) SetLimit(limit int) error {
if err := validateIntInRange(limit, 1, TribeSnapshotListMaxLimit); err != nil {
if err := validateInRange(limit, 1, TribeSnapshotListMaxLimit); err != nil {
return ValidationError{
Model: listTribeSnapshotsParamsModelName,
Field: "limit",

View File

@ -149,7 +149,7 @@ func TestNewTribeSnapshotCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "TribeSnapshotCursor",
Field: "id",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -284,7 +284,7 @@ func TestListTribeSnapshotsParams_SetTribeIDs(t *testing.T) {
Model: "ListTribeSnapshotsParams",
Field: "tribeIDs",
Index: 3,
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -842,7 +842,7 @@ func TestListTribeSnapshotsParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListTribeSnapshotsParams",
Field: "limit",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -856,7 +856,7 @@ func TestListTribeSnapshotsParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListTribeSnapshotsParams",
Field: "limit",
Err: domain.MaxLessEqualError{
Err: domain.MaxLessEqualError[int]{
Max: domain.TribeSnapshotListMaxLimit,
Current: domain.TribeSnapshotListMaxLimit + 1,
},

View File

@ -342,7 +342,7 @@ func TestNewTribeCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "TribeCursor",
Field: "id",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -364,7 +364,7 @@ func TestNewTribeCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "TribeCursor",
Field: "odScoreAtt",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -386,7 +386,7 @@ func TestNewTribeCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "TribeCursor",
Field: "odScoreDef",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -408,7 +408,7 @@ func TestNewTribeCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "TribeCursor",
Field: "odScoreTotal",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -430,7 +430,7 @@ func TestNewTribeCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "TribeCursor",
Field: "points",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -452,7 +452,7 @@ func TestNewTribeCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "TribeCursor",
Field: "mostPoints",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 0,
Current: -1,
},
@ -552,7 +552,7 @@ func TestListTribesParams_SetIDs(t *testing.T) {
Model: "ListTribesParams",
Field: "ids",
Index: 3,
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -1164,7 +1164,7 @@ func TestListTribesParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListTribesParams",
Field: "limit",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -1178,7 +1178,7 @@ func TestListTribesParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListTribesParams",
Field: "limit",
Err: domain.MaxLessEqualError{
Err: domain.MaxLessEqualError[int]{
Max: domain.TribeListMaxLimit,
Current: domain.TribeListMaxLimit + 1,
},

View File

@ -122,56 +122,56 @@ func (e SliceElementValidationError) Unwrap() error {
return e.Err
}
type MinGreaterEqualError struct {
Min int
Current int
type MinGreaterEqualError[T float32 | float64 | int] struct {
Min T
Current T
}
var _ ErrorWithParams = MinGreaterEqualError{}
var _ ErrorWithParams = MinGreaterEqualError[int]{}
func (e MinGreaterEqualError) Error() string {
return fmt.Sprintf("must be no less than %d (current: %d)", e.Min, e.Current)
func (e MinGreaterEqualError[T]) Error() string {
return fmt.Sprintf("must be no less than %v (current: %v)", e.Min, e.Current)
}
func (e MinGreaterEqualError) Type() ErrorType {
func (e MinGreaterEqualError[T]) Type() ErrorType {
return ErrorTypeIncorrectInput
}
const errorCodeMinGreaterEqual = "min-greater-equal"
func (e MinGreaterEqualError) Code() string {
func (e MinGreaterEqualError[T]) Code() string {
return errorCodeMinGreaterEqual
}
func (e MinGreaterEqualError) Params() map[string]any {
func (e MinGreaterEqualError[T]) Params() map[string]any {
return map[string]any{
"Min": e.Min,
"Current": e.Current,
}
}
type MaxLessEqualError struct {
Max int
Current int
type MaxLessEqualError[T float32 | float64 | int] struct {
Max T
Current T
}
var _ ErrorWithParams = MaxLessEqualError{}
var _ ErrorWithParams = MaxLessEqualError[int]{}
func (e MaxLessEqualError) Error() string {
return fmt.Sprintf("must be no greater than %d (current: %d)", e.Max, e.Current)
func (e MaxLessEqualError[T]) Error() string {
return fmt.Sprintf("must be no greater than %v (current: %v)", e.Max, e.Current)
}
func (e MaxLessEqualError) Type() ErrorType {
func (e MaxLessEqualError[T]) Type() ErrorType {
return ErrorTypeIncorrectInput
}
const errorCodeMaxLessEqual = "max-less-equal"
func (e MaxLessEqualError) Code() string {
func (e MaxLessEqualError[T]) Code() string {
return errorCodeMaxLessEqual
}
func (e MaxLessEqualError) Params() map[string]any {
func (e MaxLessEqualError[T]) Params() map[string]any {
return map[string]any{
"Max": e.Max,
"Current": e.Current,
@ -356,16 +356,16 @@ func validateServerKey(key string) error {
return validateStringLen(key, serverKeyMinLength, serverKeyMaxLength)
}
func validateIntInRange(current, min, max int) error {
func validateInRange[T float32 | float64 | int](current, min, max T) error {
if current < min {
return MinGreaterEqualError{
return MinGreaterEqualError[T]{
Min: min,
Current: current,
}
}
if current > max {
return MaxLessEqualError{
return MaxLessEqualError[T]{
Max: max,
Current: current,
}

View File

@ -269,7 +269,7 @@ func (params *ListVersionsParams) Limit() int {
}
func (params *ListVersionsParams) SetLimit(limit int) error {
if err := validateIntInRange(limit, 1, VersionListMaxLimit); err != nil {
if err := validateInRange(limit, 1, VersionListMaxLimit); err != nil {
return ValidationError{
Model: listVersionsParamsModelName,
Field: "limit",

View File

@ -324,7 +324,7 @@ func TestListVersionsParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListVersionsParams",
Field: "limit",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -338,7 +338,7 @@ func TestListVersionsParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListVersionsParams",
Field: "limit",
Err: domain.MaxLessEqualError{
Err: domain.MaxLessEqualError[int]{
Max: domain.VersionListMaxLimit,
Current: domain.VersionListMaxLimit + 1,
},

View File

@ -49,7 +49,7 @@ func UnmarshalVillageFromDatabase(
rawProfileURL string,
createdAt time.Time,
) (Village, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return Village{}, ValidationError{
Model: villageModelName,
Field: "id",
@ -263,7 +263,7 @@ func UnmarshalVillageMetaFromDatabase(
continent string,
rawProfileURL string,
) (VillageMeta, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return VillageMeta{}, ValidationError{
Model: villageMetaModelName,
Field: "id",
@ -423,7 +423,7 @@ type VillageCursor struct {
const villageCursorModelName = "VillageCursor"
func NewVillageCursor(id int, serverKey string) (VillageCursor, error) {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return VillageCursor{}, ValidationError{
Model: villageCursorModelName,
Field: "id",
@ -528,7 +528,7 @@ func (params *ListVillagesParams) IDs() []int {
func (params *ListVillagesParams) SetIDs(ids []int) error {
for i, id := range ids {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return SliceElementValidationError{
Model: listVillagesParamsModelName,
Field: "ids",
@ -623,7 +623,7 @@ func (params *ListVillagesParams) PlayerIDs() []int {
func (params *ListVillagesParams) SetPlayerIDs(playerIDs []int) error {
for i, id := range playerIDs {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return SliceElementValidationError{
Model: listVillagesParamsModelName,
Field: "playerIDs",
@ -644,7 +644,7 @@ func (params *ListVillagesParams) TribeIDs() []int {
func (params *ListVillagesParams) SetTribeIDs(tribeIDs []int) error {
for i, id := range tribeIDs {
if err := validateIntInRange(id, 1, math.MaxInt); err != nil {
if err := validateInRange(id, 1, math.MaxInt); err != nil {
return SliceElementValidationError{
Model: listVillagesParamsModelName,
Field: "tribeIDs",
@ -711,7 +711,7 @@ func (params *ListVillagesParams) Limit() int {
}
func (params *ListVillagesParams) SetLimit(limit int) error {
if err := validateIntInRange(limit, 1, VillageListMaxLimit); err != nil {
if err := validateInRange(limit, 1, VillageListMaxLimit); err != nil {
return ValidationError{
Model: listVillagesParamsModelName,
Field: "limit",

View File

@ -181,7 +181,7 @@ func TestNewVillageCursor(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "VillageCursor",
Field: "id",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -260,7 +260,7 @@ func TestListVillagesParams_SetIDs(t *testing.T) {
Model: "ListVillagesParams",
Field: "ids",
Index: 3,
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -545,7 +545,7 @@ func TestListVillagesParams_SetPlayerIDs(t *testing.T) {
Model: "ListVillagesParams",
Field: "playerIDs",
Index: 3,
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -605,7 +605,7 @@ func TestListVillagesParams_SetTribeIDs(t *testing.T) {
Model: "ListVillagesParams",
Field: "tribeIDs",
Index: 3,
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -814,7 +814,7 @@ func TestListVillagesParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListVillagesParams",
Field: "limit",
Err: domain.MinGreaterEqualError{
Err: domain.MinGreaterEqualError[int]{
Min: 1,
Current: 0,
},
@ -828,7 +828,7 @@ func TestListVillagesParams_SetLimit(t *testing.T) {
expectedErr: domain.ValidationError{
Model: "ListVillagesParams",
Field: "limit",
Err: domain.MaxLessEqualError{
Err: domain.MaxLessEqualError[int]{
Max: domain.VillageListMaxLimit,
Current: domain.VillageListMaxLimit + 1,
},

View File

@ -258,7 +258,7 @@ func TestListEnnoblements(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -294,7 +294,7 @@ func TestListEnnoblements(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.EnnoblementListMaxLimit,
Current: limit,
}
@ -866,7 +866,7 @@ func TestListPlayerEnnoblements(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -902,7 +902,7 @@ func TestListPlayerEnnoblements(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.EnnoblementListMaxLimit,
Current: limit,
}
@ -1532,7 +1532,7 @@ func TestListTribeEnnoblements(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -1568,7 +1568,7 @@ func TestListTribeEnnoblements(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.EnnoblementListMaxLimit,
Current: limit,
}
@ -2185,7 +2185,7 @@ func TestListVillageEnnoblements(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -2221,7 +2221,7 @@ func TestListVillageEnnoblements(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.EnnoblementListMaxLimit,
Current: limit,
}

View File

@ -192,7 +192,7 @@ func TestListPlayerPlayerSnapshots(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -228,7 +228,7 @@ func TestListPlayerPlayerSnapshots(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.PlayerSnapshotListMaxLimit,
Current: limit,
}

View File

@ -370,7 +370,7 @@ func TestListVersionPlayers(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -406,7 +406,7 @@ func TestListVersionPlayers(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.PlayerListMaxLimit,
Current: limit,
}
@ -680,7 +680,7 @@ func TestListVersionPlayers(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
id, err := strconv.Atoi(req.URL.Query().Get("id"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: id,
}
@ -1238,7 +1238,7 @@ func TestListServerPlayers(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -1274,7 +1274,7 @@ func TestListServerPlayers(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.PlayerListMaxLimit,
Current: limit,
}
@ -1548,7 +1548,7 @@ func TestListServerPlayers(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
id, err := strconv.Atoi(req.URL.Query().Get("id"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: id,
}
@ -1988,7 +1988,7 @@ func TestListTribeMembers(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -2024,7 +2024,7 @@ func TestListTribeMembers(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.PlayerListMaxLimit,
Current: limit,
}
@ -2418,7 +2418,7 @@ func TestGetPlayer(t *testing.T) {
require.Len(t, pathSegments, 8)
id, err := strconv.Atoi(pathSegments[7])
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: id,
}

View File

@ -190,7 +190,7 @@ func TestListServerServerSnapshots(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -226,7 +226,7 @@ func TestListServerServerSnapshots(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.ServerSnapshotListMaxLimit,
Current: limit,
}

View File

@ -198,7 +198,7 @@ func TestListServers(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -234,7 +234,7 @@ func TestListServers(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.ServerListMaxLimit,
Current: limit,
}

View File

@ -273,7 +273,7 @@ func TestListPlayerTribeChanges(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -309,7 +309,7 @@ func TestListPlayerTribeChanges(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.TribeChangeListMaxLimit,
Current: limit,
}
@ -965,7 +965,7 @@ func TestListTribeMemberChanges(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -1001,7 +1001,7 @@ func TestListTribeMemberChanges(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.TribeChangeListMaxLimit,
Current: limit,
}

View File

@ -192,7 +192,7 @@ func TestListTribeTribeSnapshots(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -228,7 +228,7 @@ func TestListTribeTribeSnapshots(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.TribeSnapshotListMaxLimit,
Current: limit,
}

View File

@ -327,7 +327,7 @@ func TestListTribes(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -363,7 +363,7 @@ func TestListTribes(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.TribeListMaxLimit,
Current: limit,
}
@ -789,7 +789,7 @@ func TestGetTribe(t *testing.T) {
require.Len(t, pathSegments, 8)
id, err := strconv.Atoi(pathSegments[7])
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: id,
}

View File

@ -146,7 +146,7 @@ func TestListVersions(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -182,7 +182,7 @@ func TestListVersions(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.VersionListMaxLimit,
Current: limit,
}

View File

@ -185,7 +185,7 @@ func TestListVillages(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -221,7 +221,7 @@ func TestListVillages(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.VillageListMaxLimit,
Current: limit,
}
@ -629,7 +629,7 @@ func TestListPlayerVillages(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -665,7 +665,7 @@ func TestListPlayerVillages(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.VillageListMaxLimit,
Current: limit,
}
@ -1042,7 +1042,7 @@ func TestListTribeVillages(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: limit,
}
@ -1078,7 +1078,7 @@ func TestListTribeVillages(t *testing.T) {
body := decodeJSON[apimodel.ErrorResponse](t, resp.Body)
limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
require.NoError(t, err)
domainErr := domain.MaxLessEqualError{
domainErr := domain.MaxLessEqualError[int]{
Max: domain.VillageListMaxLimit,
Current: limit,
}
@ -1363,7 +1363,7 @@ func TestGetVillage(t *testing.T) {
require.Len(t, pathSegments, 8)
id, err := strconv.Atoi(pathSegments[7])
require.NoError(t, err)
domainErr := domain.MinGreaterEqualError{
domainErr := domain.MinGreaterEqualError[int]{
Min: 1,
Current: id,
}