language

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package language is used to compile and run untrusted code securely. The heavy lifting is done by the great isolate library. This library comes with a lot of built-in languages, and it's easy to implement your own languages.

Index

Constants

This section is empty.

Variables

View Source
var ErrorLanguageNotFound = errors.New("language not found")

Functions

This section is empty.

Types

type Language

type Language interface {
	ID() string
	DisplayName() string
	DefaultFilename() string
	Compile(ctx context.Context, s sandbox.Sandbox, f sandbox.File, stderr io.Writer, extras []sandbox.File) (*sandbox.File, error) //TODO remove extras?
	Run(ctx context.Context, s sandbox.Sandbox, binary sandbox.File, stdin io.Reader, stdout io.Writer, tl time.Duration, ml memory.Amount) (*sandbox.Status, error)
}

Language is the main building block of this package, it's used to compile a source file and then run the resulting binary.

func ListExcept added in v0.4.0

func ListExcept(s Store, except []string) []Language

ListExcept returns a slice of languages except some.

type ListStore

type ListStore struct {
	LanguageList []Language
}

ListStore is a basic implementation (and probably only realistic, so maybe an interface is not really necessary) of a Store.

func NewListStore

func NewListStore() *ListStore

func (*ListStore) Get

func (m *ListStore) Get(id string) (Language, error)

func (*ListStore) List

func (m *ListStore) List() []Language

func (*ListStore) Register

func (m *ListStore) Register(id string, l Language)

type NotFoundError added in v0.4.0

type NotFoundError struct {
	ID string
}

func (NotFoundError) Error added in v0.4.0

func (n NotFoundError) Error() string

func (NotFoundError) Is added in v0.4.0

func (n NotFoundError) Is(err error) bool

type Store

type Store interface {
	Register(id string, l Language)
	List() []Language
	Get(id string) (Language, error)
}

Store is an interface which is used to capture the notion of storing languages. Via it's Store.Register method it's possible to override the underlying ID of the language for the outside world.

var DefaultStore Store

DefaultStore is a store which all Language objects should register themselves in.

type Test added in v0.4.0

type Test struct {
	Name            string
	Language        Language
	Source          string
	Input           string
	ExpectedOutput  string
	ExpectedVerdict sandbox.Verdict
	TimeLimit       time.Duration
	MemoryLimit     memory.Amount
}

Test is a struct that holds a test for a language.

func (Test) Run added in v0.4.0

func (test Test) Run(s sandbox.Sandbox) error

Run the test given a sandbox.

type Testable added in v0.4.0

type Testable interface {
	Test(*testing.T, sandbox.Sandbox) error
}

Testable is an interface that can be used to test Languages by providing a sandbox.Sandbox This will probably run a bunch of tests (most likely via defining multiple Test objects and calling Test.Run).

type Wrapper added in v0.4.0

type Wrapper struct {
	IDWrapper string
	Language
}

Wrapper overrides a Language's ID.

func (Wrapper) ID added in v0.4.0

func (w Wrapper) ID() string

Directories

Path Synopsis
langs
cpp
nim
zip
Package sandbox declares the Sandbox interface which can be used to run untrusted code.
Package sandbox declares the Sandbox interface which can be used to run untrusted code.

Jump to

Keyboard shortcuts

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