task

package
v0.0.0-...-5e79c25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const RuntimePath = "/runtime"

Variables

View Source
var LangRunners = []runner{
	{
		Name:            "go",
		Ext:             ".go",
		Image:           "golang:1.15-alpine",
		BuildCmd:        "rm -rf go.mod && go mod init code-runner && go build -v .",
		RunCmd:          "./code-runner",
		Env:             []string{"GOPROXY=https://goproxy.io,direct"},
		DefaultFileName: "code.go",
		MaxCPUs:         2,
		MaxMemory:       100,
		Example: "package main\n\n" +
			"import \"fmt\"\n\n" +
			"func main() {\n\n" +
			"  fmt.Println(\"hello world.\")\n\n" +
			"}",
	},
	{
		Name:            "python",
		Ext:             ".py",
		Image:           "python:3.9.1-alpine",
		BuildCmd:        "",
		RunCmd:          "python3 code.py",
		Env:             []string{},
		DefaultFileName: "code.py",
		MaxCPUs:         2,
		MaxMemory:       100,
		Example:         "print(\"hello world.\")",
	},
	{
		Name:            "java",
		Ext:             ".java",
		Image:           "openjdk:8u232-jdk",
		BuildCmd:        "javac code.java",
		RunCmd:          "java code",
		Env:             []string{},
		DefaultFileName: "code.java",
		MaxCPUs:         2,
		MaxMemory:       100,
		Example:         "class code {\n  public static void main(String[] args) {\n    System.out.println(\"Hello, World!\"); \n  }\n}",
	},
	{
		Name:            "javascript",
		Ext:             ".js",
		Image:           "node:lts-alpine",
		BuildCmd:        "npm config set registry https://registry.npm.taobao.org",
		RunCmd:          "node code.js",
		Env:             []string{},
		DefaultFileName: "code.js",
		MaxCPUs:         2,
		MaxMemory:       50,
		Example:         "console.log(\"hello world.\");",
	},
	{
		Name:            "c",
		Ext:             ".c",
		Image:           "gcc:latest",
		BuildCmd:        "gcc -v code.c -o code",
		RunCmd:          "./code",
		Env:             []string{},
		DefaultFileName: "code.c",
		MaxCPUs:         2,
		MaxMemory:       50,
		Example:         "#include <stdio.h>\nint main()\n{\n  printf(\"Hello, World!\");\n  return 0;\n}",
	},
}
View Source
var SandboxMap = make(map[string]Sandbox)

Functions

This section is empty.

Types

type Output

type Output struct {
	Error bool   `json:"error"`
	Body  string `json:"body"`
}

type Sandbox

type Sandbox struct {
	T           *Task
	LastOptTime time.Time
}

type Task

type Task struct {
	UUID   string
	RUNNER *runner

	ContainerID string

	SourceVolumePath string // Folder in Host: /home/<your_user>/coderunner/volume/<UUID>/
	// contains filtered or unexported fields
}

func NewTask

func NewTask(language string, code []byte) (*Task, error)

func (*Task) Clean

func (t *Task) Clean()

func (*Task) CreateFile

func (t *Task) CreateFile(code string, fileName string) (*Output, error)

func (*Task) Exec

func (t *Task) Exec(cmd string, fileName string) (*Output, error)

func (*Task) Run

func (t *Task) Run() ([]*Output, error)

Run runs a task.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL