Documentation ¶
Index ¶
- Variables
- func AutoMigrateDb()
- func DeleteBaseContestByID(id uint) error
- func DeleteContestByID(id uint) error
- func DeleteContestantByID(id uint) error
- func DeleteGameByID(id uint) error
- func DeleteSdkByID(id uint) error
- func GetMatchNumByBaseContestID(baseContestID uint) (uint, error)
- func GetVerificationCode(email string) (string, error)
- func InitDb()
- func InitRedis()
- func SaveVerificationCode(code string, email string, expireInMinutes int) error
- func UpdateAiByID(id uint, updates map[string]interface{}) error
- func UpdateBaseContestByID(id uint, updates map[string]interface{}) error
- func UpdateContestByID(id uint, updates map[string]interface{}) error
- func UpdateContestantByID(id uint, updates map[string]interface{}) error
- func UpdateGameByID(id uint, updates map[string]interface{}) error
- func UpdateMatchByID(id uint, updates map[string]interface{}) error
- func UpdateSdkByID(id uint, updates map[string]interface{}) error
- func UpdateUserByEmail(email string, updates map[string]interface{}) error
- func UpdateUserByID(id uint, updates map[string]interface{}) error
- func UpdateUserByUsername(username string, updates map[string]interface{}) error
- func UpsertUser(user User)
- type Ai
- type BaseContest
- func (bc *BaseContest) AddAdmin(userID uint) error
- func (bc *BaseContest) Create(adminIDs []uint) error
- func (bc *BaseContest) Delete() error
- func (bc *BaseContest) DeleteContestantByUserID(userID uint) error
- func (bc *BaseContest) GetAdmins() ([]User, error)
- func (bc *BaseContest) GetAis(query QueryParams, preload bool) ([]Ai, int64, error)
- func (bc *BaseContest) GetContestantByUserID(userID uint, preloads []PreloadQuery) (Contestant, error)
- func (bc *BaseContest) GetContestants(preloads []PreloadQuery) ([]Contestant, error)
- func (bc *BaseContest) GetMatches(query QueryParams, preload bool) ([]Match, int64, error)
- func (bc *BaseContest) GetSdks(fields ...string) (sdks []Sdk, err error)
- func (bc *BaseContest) IsAdmin(userID uint) (bool, error)
- func (bc *BaseContest) RemoveAdmin(userID uint) error
- func (bc *BaseContest) Update(updates map[string]interface{}) error
- func (bc *BaseContest) UpdateContestantByUserID(userID uint, updates map[string]interface{}) error
- type Contest
- type ContestPrivilege
- type ContestStates
- type Contestant
- type ContestantPermissions
- type DockerTask
- type Game
- type GameLogic
- type GamePrivilege
- type GlobalPermissions
- type Match
- type MatchDetail
- type MatchType
- type Metadata
- type PreloadQuery
- type QueryParams
- type Registration
- type Sdk
- type TaskState
- type TaskStatus
- type User
Constants ¶
This section is empty.
Variables ¶
var Ctx = context.Background()
var Rdb *redis.Client
Functions ¶
func DeleteBaseContestByID ¶
func DeleteContestByID ¶
func DeleteContestantByID ¶
func DeleteGameByID ¶
func DeleteSdkByID ¶
func GetVerificationCode ¶
func SaveVerificationCode ¶
func UpdateAiByID ¶
func UpdateBaseContestByID ¶
func UpdateContestByID ¶
func UpdateContestantByID ¶
func UpdateGameByID ¶
func UpdateMatchByID ¶
func UpdateSdkByID ¶
func UpdateUserByEmail ¶
func UpdateUserByID ¶
func UpdateUserByUsername ¶
func UpsertUser ¶
func UpsertUser(user User)
UpsertUser upserts a user. If the user exists(determined by username), update its password. If the user does not exist, create it.
Types ¶
type Ai ¶
type Ai struct { gorm.Model BaseContestID uint `gorm:"not null;index"` UserID uint `gorm:"not null;index"` User User `gorm:"foreignKey:UserID"` SdkID uint `gorm:"not null"` Sdk Sdk `gorm:"foreignKey:SdkID"` Note string Status TaskStatus `gorm:"embedded;embeddedPrefix:task_"` // snapshot fields GameID uint }
func GetAis ¶
func GetAis(query QueryParams, preload bool) (ais []Ai, count int64, err error)
If preload is true, the following fields will be preloaded: Sdk, User
type BaseContest ¶
type BaseContest struct { gorm.Model GameID uint `gorm:"not null;index"` States ContestStates `gorm:"embedded"` Script string Admins []User `gorm:"many2many:base_contest_admins;"` }
func GetBaseContestByID ¶
func GetBaseContestByID(id uint) (bc BaseContest, err error)
func (*BaseContest) AddAdmin ¶
func (bc *BaseContest) AddAdmin(userID uint) error
func (*BaseContest) Create ¶
func (bc *BaseContest) Create(adminIDs []uint) error
Necessary fields: GameID Optional fields: Script, States
func (*BaseContest) Delete ¶
func (bc *BaseContest) Delete() error
func (*BaseContest) DeleteContestantByUserID ¶
func (bc *BaseContest) DeleteContestantByUserID(userID uint) error
func (*BaseContest) GetAdmins ¶
func (bc *BaseContest) GetAdmins() ([]User, error)
func (*BaseContest) GetAis ¶
func (bc *BaseContest) GetAis(query QueryParams, preload bool) ([]Ai, int64, error)
func (*BaseContest) GetContestantByUserID ¶
func (bc *BaseContest) GetContestantByUserID(userID uint, preloads []PreloadQuery) (Contestant, error)
func (*BaseContest) GetContestants ¶
func (bc *BaseContest) GetContestants(preloads []PreloadQuery) ([]Contestant, error)
Sorted by points in descending order. Currently supported preloads: "User", "AssignedAi"
func (*BaseContest) GetMatches ¶
func (bc *BaseContest) GetMatches(query QueryParams, preload bool) ([]Match, int64, error)
func (*BaseContest) GetSdks ¶
func (bc *BaseContest) GetSdks(fields ...string) (sdks []Sdk, err error)
func (*BaseContest) RemoveAdmin ¶
func (bc *BaseContest) RemoveAdmin(userID uint) error
func (*BaseContest) Update ¶
func (bc *BaseContest) Update(updates map[string]interface{}) error
func (*BaseContest) UpdateContestantByUserID ¶
func (bc *BaseContest) UpdateContestantByUserID(userID uint, updates map[string]interface{}) error
type Contest ¶
type Contest struct { gorm.Model BaseContest BaseContest `gorm:"foreignKey:ID"` Metadata Metadata `gorm:"embedded"` Registration Registration `gorm:"embedded"` RegisteredUsers []User `gorm:"many2many:contest_registrations;"` }
func GetContests ¶
func (*Contest) Create ¶
Optional fields: Metadata, Registration, BaseContest.Script, BaseContest.States
func (*Contest) GetPrivilege ¶
func (c *Contest) GetPrivilege(userID uint) (ContestPrivilege, error)
type ContestPrivilege ¶
type ContestPrivilege string
const ( ContestPrivilegeAdmin ContestPrivilege = "admin" ContestPrivilegeRegistered ContestPrivilege = "registered" ContestPrivilegeUnregistered ContestPrivilege = "unregistered" )
type ContestStates ¶
type ContestStates struct { AssignAiEnabled bool `gorm:"default: false"` CommitAiEnabled bool `gorm:"default: false"` ContestScriptEnvironmentEnabled bool `gorm:"default: false"` PrivateMatchEnabled bool `gorm:"default: false"` PublicMatchEnabled bool `gorm:"default: false"` TestMatchEnabled bool `gorm:"default: false"` }
type Contestant ¶
type Contestant struct { gorm.Model BaseContestID uint `gorm:"not null;index"` UserID uint `gorm:"not null;index"` User User `gorm:"foreignKey:UserID"` Performance string // editable by contest script Permissions ContestantPermissions `gorm:"embedded"` Points int // AssignedAiID is 0 if the contestant doesn't assign an AI. AssignedAiID uint AssignedAi Ai `gorm:"foreignKey:AssignedAiID"` }
func GetContestant ¶
func GetContestant(condition map[string]interface{}, preloads []PreloadQuery) (Contestant, error)
func GetContestantByID ¶
func GetContestantByID(id uint, preloads []PreloadQuery) (Contestant, error)
func GetContestants ¶
func GetContestants(filter map[string]interface{}, preloads []PreloadQuery) ([]Contestant, error)
Sorted by points in descending order. Currently supported preloads: "User", "AssignedAi"
func (*Contestant) Create ¶
func (c *Contestant) Create() error
Necessary fields: BaseContestID, UserID Optional fields: Performance, Permissions, Points, AssignedAiID
func (*Contestant) Delete ¶
func (c *Contestant) Delete() error
func (*Contestant) Update ¶
func (c *Contestant) Update(updates map[string]interface{}) error
type ContestantPermissions ¶
type DockerTask ¶
type DockerTask struct { Dockerfile string Status TaskStatus `gorm:"embedded"` }
type Game ¶
type Game struct { gorm.Model BaseContest BaseContest `gorm:"foreignKey:ID"` Metadata Metadata `gorm:"embedded"` // game assets GameLogic GameLogic `gorm:"embedded;embeddedPrefix:game_logic_"` MatchDetail MatchDetail `gorm:"embedded;embeddedPrefix:match_detail_"` }
func (*Game) Create ¶
Optional fields: Metadata, GameLogic, MatchDetail, BaseContest.Script, BaseContest.States
func (*Game) GetPrivilege ¶
func (g *Game) GetPrivilege(userID uint) (GamePrivilege, error)
Note: Game doesn't need registration
type GameLogic ¶
type GameLogic struct { Build DockerTask `gorm:"embedded;embeddedPrefix:build_"` Run DockerTask `gorm:"embedded;embeddedPrefix:run_"` Status TaskStatus `gorm:"embedded"` }
type GamePrivilege ¶
type GamePrivilege string
const ( GamePrivilegeAdmin GamePrivilege = "admin" GamePrivilegeRegistered GamePrivilege = "registered" )
type GlobalPermissions ¶
type GlobalPermissions struct {
CanCreateGameOrContest bool `gorm:"default: false"`
}
type Match ¶
type Match struct { gorm.Model BaseContestID uint `gorm:"not null;index"` Ais []Ai `gorm:"many2many:match_ais;"` State TaskState Tag string Scores []int `gorm:"serializer:json"` // Customized Info string passed to game logic. JSON format. ExtraInfo string MatchType MatchType `gorm:"default: public"` // snapshot fields GameID uint }
func GetMatchByID ¶
If preload is true, the following fields will be preloaded: Ais, Ais.Usergi
func GetMatches ¶
func GetMatches(query QueryParams, preload bool) (matches []Match, count int64, err error)
Sorted by id in descending order. If preload is true, the following fields will be preloaded: Ais, Ais.User
type MatchDetail ¶
type MatchDetail struct {
Template string
}
type PreloadQuery ¶
type QueryParams ¶
type Registration ¶
type Sdk ¶
type Sdk struct { gorm.Model BaseContestID uint `gorm:"not null;index"` Name string `gorm:"not null"` Readme string BuildAi DockerTask `gorm:"embedded;embeddedPrefix:build_ai_"` RunAi DockerTask `gorm:"embedded;embeddedPrefix:run_ai_"` }
type TaskStatus ¶
func (*TaskStatus) BeforeSave ¶
func (ts *TaskStatus) BeforeSave(tx *gorm.DB) (err error)
BeforeSave truncates the message to 1000 characters.
type User ¶
type User struct { gorm.Model AvatarURL string Bio string Department string Email string `gorm:"uniqueIndex,not null"` Name string Nickname string `gorm:"index"` Password []byte `gorm:"not null"` Permissions GlobalPermissions `gorm:"embedded"` School string Username string `gorm:"uniqueIndex,not null"` ContestRegistered []Contest `gorm:"many2many:contest_registrations;"` }
func SearchUsers ¶
func (*User) Create ¶
Necessary fields: Username, Email, Password Optional fields: AvatarURL, Bio, Department, Name, Nickname, School, Permissions