Documentation ¶
Index ¶
- Constants
- Variables
- type Challenge
- type ChallengeCreateWithTestcaseDTO
- type ChallengeExtended
- type ChallengePaginationOptions
- type ChallengeTestcase
- type ChallengeTestcaseDTO
- type ChallengeUpdateDTO
- type HttpBadRequest
- type HttpError
- type JWTClaims
- type PaginationOptions
- type PaginationResult
- type SandboxInstance
- type SandboxInstruction
- type SandboxRunResult
- type Submission
- type SubmissionCreateDTO
- type SubmissionPaginationOptions
- type SubmissionTestcase
- type User
- type UserLoginDTO
- type UserLoginResponse
- type UserRegisterDTO
- type UserRegisterResponse
- type UserUpdateRoleDTO
Constants ¶
View Source
const ( SandboxMemoryMB uint = 1024 * 1024 SandboxMemoryGB uint = 1024 * SandboxMemoryMB )
View Source
const ( SubmissionStatusPending = "PENDING" SubmissionStatusCorrect = "CORRECT" SubmissionStatusWrong = "WRONG" SubmissionStatusNotSolve = "NOTSOLVE" )
View Source
const ( UserRoleAdmin = "ADMIN" UserRoleStaff = "STAFF" UserRoleUser = "USER" )
Variables ¶
View Source
var CCodeExample = `` /* 136-byte string literal not displayed */
View Source
var CInstructionBook = SandboxInstruction{
Language: "c",
DockerImage: "docker.io/library/gcc:12.3.0",
CompileCmd: "cp /sandbox/code /sandbox/main.c && gcc -o /sandbox/main /sandbox/main.c",
RunCmd: "/sandbox/main < /stdin/stdin",
CompileTimeout: 1000 * 60,
}
View Source
var GoCodeExample = `` /* 345-byte string literal not displayed */
View Source
var GoInstructionBook = SandboxInstruction{
Language: "go",
DockerImage: "docker.io/library/golang:1.21",
CompileCmd: "cd /sandbox && cp /sandbox/code /sandbox/main.go && go mod init sandbox && go build -o /sandbox/main",
RunCmd: "/sandbox/main < /stdin/stdin",
CompileTimeout: 1000 * 60,
}
View Source
var LanguageInstructionMap = map[string]SandboxInstruction{ "python": PythonInstructionBook, "go": GoInstructionBook, "c": CInstructionBook, }
View Source
var PythonCodeExample = `
x = int(input())
y = int(input())
print(x + y)
`
View Source
var PythonCodeOOMTestCode = `
data = []
while True:
data.append(' ' * 10**6)
`
View Source
var PythonCodeTimeoutTestCode = `
import time
time.sleep(2)
`
View Source
var PythonInstructionBook = SandboxInstruction{
Language: "python",
DockerImage: "docker.io/library/python:3.10",
CompileCmd: "cp /sandbox/code /sandbox/code.py",
RunCmd: "python3 /sandbox/code.py < /stdin/stdin",
CompileTimeout: 1000,
}
Functions ¶
This section is empty.
Types ¶
type Challenge ¶
type Challenge struct { ID uint `json:"challenge_id" gorm:"primaryKey"` Name string `json:"name"` Description string `json:"description"` UserID uint `json:"user_id"` User *User `json:"user" gorm:"foreignKey:UserID"` Testcases []*ChallengeTestcase `json:"testcases" gorm:"foreignKey:ChallengeID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"` Submission []*Submission `json:"submission" gorm:"foreignKey:ChallengeID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"` }
type ChallengeCreateWithTestcaseDTO ¶
type ChallengeCreateWithTestcaseDTO struct { Name string `json:"name" validate:"required,min=3,max=255"` Description string `json:"description" validate:"max=3000"` Testcases []ChallengeTestcaseDTO `json:"testcases" validate:"required"` }
func ValidateChallengeCreateWithTestcaseDTO ¶
func ValidateChallengeCreateWithTestcaseDTO(c *fiber.Ctx) ChallengeCreateWithTestcaseDTO
func (*ChallengeCreateWithTestcaseDTO) GetTestcases ¶
func (c *ChallengeCreateWithTestcaseDTO) GetTestcases() []*ChallengeTestcase
type ChallengeExtended ¶
type ChallengePaginationOptions ¶
type ChallengePaginationOptions struct { PaginationOptions User *User }
type ChallengeTestcase ¶
type ChallengeTestcase struct { ID uint `json:"testcase_id" gorm:"primaryKey"` Input string `json:"input"` ExpectedOutput string `json:"expected_output"` LimitMemory uint `json:"limit_memory"` LimitTimeMs uint `json:"limit_time_ms"` SubmissionTestcases []*SubmissionTestcase `json:"submission_testcases"` ChallengeID uint `json:"challenge_id"` Challenge *Challenge `json:"challenge"` ActionFlag string `json:"-" gorm:"-"` }
type ChallengeTestcaseDTO ¶
type ChallengeTestcaseDTO struct { ID uint `json:"testcase_id" validate:"required,number"` Input string `json:"input" validate:"required,max=1024"` ExpectedOutput string `json:"expected_output" validate:"required,max=1024"` LimitMemory uint `json:"limit_memory" validate:"required"` LimitTimeMs uint `json:"limit_time_ms" validate:"required"` Action string `json:"action" validate:"required,oneof=create update delete"` }
func (*ChallengeTestcaseDTO) ToTestcase ¶
func (t *ChallengeTestcaseDTO) ToTestcase() *ChallengeTestcase
type ChallengeUpdateDTO ¶
type ChallengeUpdateDTO struct { Name string `json:"name" validate:"required,min=3,max=255"` Description string `json:"description" validate:"max=3000"` Testcases []ChallengeTestcaseDTO `json:"testcases" validate:"required"` }
func ValidateChallengeUpdateDTO ¶
func ValidateChallengeUpdateDTO(c *fiber.Ctx) ChallengeUpdateDTO
func (*ChallengeUpdateDTO) GetTestcases ¶
func (c *ChallengeUpdateDTO) GetTestcases() []*ChallengeTestcase
type HttpBadRequest ¶
type PaginationOptions ¶
type PaginationResult ¶
type SandboxInstance ¶
type SandboxInstruction ¶
type SandboxInstruction struct { Language string DockerImage string CompileCmd string RunCmd string CompileTimeout uint }
func GetSandboxInstructionByLanguage ¶
func GetSandboxInstructionByLanguage(language string) *SandboxInstruction
type SandboxRunResult ¶
type Submission ¶
type Submission struct { ID uint `json:"submission_id" gorm:"primaryKey"` Language string `json:"language"` Code string `json:"code"` Status string `json:"status" gorm:"default:PENDING"` UserID uint `json:"user_id"` User *User `json:"user"` ChallengeID uint `json:"challenge_id"` Challenge *Challenge `json:"challenge"` SubmissionTestcases []*SubmissionTestcase `json:"submission_testcases" gorm:"foreignKey:SubmissionID;constraint:OnDelete:CASCADE"` }
func (*Submission) IsCorrect ¶
func (s *Submission) IsCorrect() bool
type SubmissionCreateDTO ¶
type SubmissionCreateDTO struct { ChallengeID uint `json:"challenge_id" validate:"required"` Language string `json:"language" validate:"required"` Code string `json:"code" validate:"required"` }
func ValidateSubmissionCreateDTO ¶
func ValidateSubmissionCreateDTO(c *fiber.Ctx) SubmissionCreateDTO
type SubmissionPaginationOptions ¶
type SubmissionPaginationOptions struct { PaginationOptions User *User Challenge *Challenge }
type SubmissionTestcase ¶
type SubmissionTestcase struct { ID uint `json:"submission_testcase_id" gorm:"primaryKey"` Status string `json:"status" gorm:"default:PENDING"` Output string `json:"output"` SubmissionID uint `json:"submission_id"` Submission *Submission `json:"submission"` ChallengeTestcaseID uint `json:"challenge_testcase_id"` ChallengeTestcase *ChallengeTestcase `json:"challenge_testcase" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"` Note string `json:"note"` }
type User ¶
type User struct { ID uint `json:"id" gorm:"primarykey"` DisplayName string `json:"displayname" gorm:"unique;not null"` Password string `json:"-" gorm:"not null"` Email string `json:"email" gorm:"unique;not null"` Role string `json:"role" gorm:"not null;default:USER"` CreatedAt time.Time `json:"-" gorm:"autoCreateTime"` }
type UserLoginDTO ¶
type UserLoginDTO struct { Password string `json:"password" validate:"required,min=6,max=32"` Email string `json:"email" validate:"required,email,min=6,max=50"` }
func ValidateUserLoginDTO ¶
func ValidateUserLoginDTO(c *fiber.Ctx) UserLoginDTO
type UserLoginResponse ¶
type UserLoginResponse struct { Token string `json:"token"` UserRegisterResponse }
type UserRegisterDTO ¶
type UserRegisterDTO struct { DisplayName string `json:"displayname" validate:"required,min=3,max=32"` Password string `json:"password" validate:"required,min=6,max=32"` Email string `json:"email" validate:"required,email,min=6,max=50"` }
func ValidateUserRegisterDTO ¶
func ValidateUserRegisterDTO(c *fiber.Ctx) UserRegisterDTO
type UserRegisterResponse ¶
type UserUpdateRoleDTO ¶
type UserUpdateRoleDTO struct { UserID uint `json:"userid" validate:"required"` Role string `json:"role" validate:"required,oneof=ADMIN STAFF USER"` }
func ValidateUserUpdateRoleDTO ¶
func ValidateUserUpdateRoleDTO(c *fiber.Ctx) UserUpdateRoleDTO
Click to show internal directories.
Click to hide internal directories.