Documentation ¶
Overview ¶
Package godge is used to build online judges for workshops and meetups. You define the tasks of the workshop along with the tests for each task. Users submit their submission with the command line client which then get judged and displayed on the scoreboard.
An example for testing that the users are able to print to stdout and use flags: https://github.com/MohamedBassem/godge/blob/master/example/example.go
Index ¶
- type ErrorResponse
- type Errors
- type Executor
- type GoExecutor
- func (b *GoExecutor) DieEvent() chan struct{}
- func (g *GoExecutor) Execute(args []string) error
- func (b *GoExecutor) ReadFileFromContainer(path string) (string, error)
- func (b *GoExecutor) StartEvent() chan struct{}
- func (b *GoExecutor) Stderr() (string, error)
- func (b *GoExecutor) Stdout() (string, error)
- func (b *GoExecutor) Stop() error
- type RegisterRequest
- type Server
- type Submission
- type SubmissionResponse
- type Task
- type Test
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
}
ErrorResponse represents an error that's returned in the http request in case of a non success code. It's exposed to be used by the command line client.
type Errors ¶
type Errors []error
Errors represents a collection of errors.
func (Errors) ErrorOrNil ¶
ErrorOrNil returns nill if there is no error, otherwise returns the error.
type Executor ¶
type Executor interface { // Excutes the submitted code with the provided arguments. Execute(args []string) error // Reads a certain file from the container's workspace. ReadFileFromContainer(path string) (string, error) // Returns the contents of the stdout of the container. Stdout() (string, error) // Returns the contents for the stderr of the container. Stderr() (string, error) // Stops the running binary. Stop() error // A channels that gets signaled when the container starts. StartEvent() chan struct{} // A channels that gets signaled when the container dies. DieEvent() chan struct{} // contains filtered or unexported methods }
Executor is used to interact with the submission.
type GoExecutor ¶
type GoExecutor struct { // A zip archive containing the "main" package to be executed. PackageArchive []byte `json:"packageArchive"` // contains filtered or unexported fields }
GoExecutor implements the Executor interface. It's used in the submit request when the language is Go. You won't deal with the GoExecutor directly, it's only exposed to be used by the command line client.
func (*GoExecutor) DieEvent ¶
func (b *GoExecutor) DieEvent() chan struct{}
DieEvent returns a channel that gets signaled when the container dies.
func (*GoExecutor) Execute ¶
func (g *GoExecutor) Execute(args []string) error
Execute executes the Go main package submitted with the given arguments.
func (*GoExecutor) ReadFileFromContainer ¶
ReadFileFromContainer reads a certain file from the container's workspace. The path is relative to the container's workdir.
func (*GoExecutor) StartEvent ¶
func (b *GoExecutor) StartEvent() chan struct{}
StartEvent returns a channel that gets signaled when the container starts.
type RegisterRequest ¶
RegisterRequest represents the registeration request. It's exposed to be used by the command line client.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server holds all the information related to a single instance of the judge. It's used to register Tasks and start the HTTP server.
func NewServer ¶
NewServer creates a new instance of the judge. It takes the address that the judge will listen to and the address of the address daemon (e.g. unix:///var/run/docker.sock). NewServer returns an error if it fails to connect to the docker daemon or with the sqlite db.
func (*Server) RegisterTask ¶
RegisterTask registers a new task in the server.
type Submission ¶
type Submission struct { // The language of the submission. Language string `json:"language"` // The task this submission is sent to. TaskName string `json:"taskName"` // The username of the submitter. Username string `json:"username"` // The executor interface to deal with the submission. Executor Executor `json:"submission"` // contains filtered or unexported fields }
Submission is the input of the user defined task tests.
func (*Submission) UnmarshalJSON ¶
func (s *Submission) UnmarshalJSON(d []byte) error
UnmarshalJSON is a custom JSON unmarshaller. It's used mainly to create a new executor instance based on the language field of the submission.
type SubmissionResponse ¶
SubmissionResponse is the response returned back by the server in response to the submission request. It's exposed to be used by the command line client.
type Task ¶
type Task struct { // The name of the task that the user will use to submit their submission. Name string `json:"name"` // A description of what's required in order to pass the task. Desc string `json:"desc"` // A group of tests that a submission needs to pass in order to pass the task. Tests []Test `json:"-"` }
Task defines a group of related tests. The user needs to pass all the tests to pass the task and get its point on the scoreboard.
type Test ¶
type Test struct { // The name of the test, which will be returned to the user when the test // fails. Name string // The actuall test. It takes a submission as an input (along with its excutor) // and should return a descriptive error when the submission don't pass the test. Func func(*Submission) error }
Test defines on of the tests of a certain task.