gopherscript

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: MIT Imports: 21 Imported by: 0

README

Gopherscript

Gopherscript is a secure scripting/configuration language written in Go. It features a fined-grain permission system and enforces a strong isolation of dependencies. Gopherscript is not production ready yet : if you find a bug or want to suggest a feature create an issue please !

Join the official community on Revolt. If you prefer to use Discord I am active in this server about Golang.

Security & Minimalism

  • The codebase is small on purpose (a single Go file with less than 7K lines and only std lib dependencies). See Implementation.
  • The default global scope has ZERO variables/functions and there are no "builtin modules" to import. (only add what you need from Golang)
  • A strict but extensive permission system allows you to precisely control what is allowed (almost no permissions by default). For more details go to the permission section.
  • Paths, path patterns, URLs are literals and dynamic paths are only possible as path expressions. You cannot create them from strings at runtime ! That facilitates the listing of permissions and helps static analysis.
  • Properties cannot be accessed with a dynamic name ( $obj[$name] ), only Go functions that are passed objects in can (you have to trust them anyway).
  • In a general way some features will be added (or refused) to limit code obfuscation.

If you find Gopherscript too restrictive don't worry ! A lax mode might be introduced in the future.

Installation & Usage

You can use the gos executable to execute scripts or launch a REPL:

go install github.com/debloat-dev/Gopherscript/cmd/gos@v0.3.1

See the documentation here. You can also use Gopherscript as a library and only add whay you need to the global scope (see the example further below).

Editor support

If you use VSCode you can install the extension of ID xbsd.gopherscript . If you are a NeoVim user, check this repo please.

Example

Example of using Gopherscript as a library from Golang:

package main

import (
	gos "github.com/debloat-dev/Gopherscript"
	"log"
)

type User struct {
	Name string
}

func main() {
   	//we create a Context that contains the granted permissions
	grantedPerms := []gos.Permission{
		gos.GlobalVarPermission{gos.UsePerm, "*"},
	}
	ctx := gos.NewContext(grantedPerms, nil)

    	//we create the initial state with the globals we want to expose
    	//the state can be re used several times (and with different modules)
	state := gos.NewState(ctx, map[string]interface{}{
		"makeUser": func(ctx *gos.Context) User {
			return User{Name: "Bar"}
		},
	})

	mod, err := gos.ParseAndCheckModule(`
            # permissions must be requested at the top of the file AND granted
            require {
                use: {globals: "*"} 
            }
            a = 1
            user = makeUser()
            return [
                ($a + 2),
                $user.Name
            ]
        `, "")
	
	if err != nil {
		log.Panicln(err)
	}

	//we execute the script
	res, err := gos.Eval(mod, state)
	if err != nil {
		log.Panicln(err)
	}

	log.Printf("%#v", res)
}

You can learn more about the interactions between Gopherscript and Golang here.

Features

The most important features are described in this section. If you want to learn Gopherscript or want to know more details about specific features you can go on the wiki.

Basic

image

Permissions

Required permissions are specified at the top of each module (file).

image

There are several permission kinds: Create, Update, Read, Delete, Use, Consume, Provide. Some permission types are already provided: FilesystemPermission, HttpPermission, StackPermission, GlobalVarPermission. You can specify your own permissions by implementing the Permission interface (Golang).

type Permission interface {
	Kind() PermissionKind
	Includes(Permission) bool
}

Gopherscript also provides limitations to prevent a script to take all resources. In the example below writing to the filesystem is limited to 100 kB/s.

require {
    
    [...]

    limits: {
        "fs/write": 100kB/s
    }
}
Special literals & expressions
# Path literals
/home/user/
./file.json

# Path expressions
/home/user/$dirpath$

# Path patterns support basic globbing (*, [set], ?) and prefixing (not both at the same time).
./data/*.json
/app/logs/...
/app/*/...     		# invalid (this might be allowed in the future though)

# HTTP host literals
https://example.com
https://example.com:443

# HTTP host pattern literals
https://*               # any HTTPS host
https://*.com           # any domain with .com as TLD, will not match against subdomains
https://*.example.com   # any subdomain of example.com

# URL literals
https://example.com/
https://example.com/index.html
https://localhost/

# URL expressions
https://example.com/users/$id$

# URL pattern literals (only prefix patterns supported)
https://example.com/users/...
Quantity literals
10s		# time.Duration
10ms		# time.Duration
10%		# 0.10

sleep 100ms
Imports

Syntax:

import <varname> <url> <file-content-sha256>  { <global variables> } allow { <permission> }

Importing a module is like executing a script with the passed globals and granted permissions.

# content of https://example.com/return_1.gos
return 1

Script:

image

Routines

Routines are mainly used for concurrent work and isolation. Each routine has its own goroutine and state.

Syntax for spawning routines:

$routine = sr [group] <globals> <module | call | variable>

Call (all permissions are inherited).

$routine = sr nil f()

Embedded module:

image

You can wait for the routine's result by calling the WaitResult method:

$result = $routine.WaitResult()!

Routines can optionally be part of a "routine group" that allows easier control of multiple routines. The group variable is defined (and updated) when the spawn expression is evaluated.

for (1 .. 10) {
    sr req_group nil read(https://debloat.dev/fakeapp/users)!
}

$results = $req_group.WaitAllResults()!

For more details about the different features you can read the repository's wiki.

Implementation

  • Why use a tree walk interpreter instead of a bytecode interpreter ?
    -> Tree walk interpreters are slower but simpler : that means less bugs and vulnerabilities. A Gopherscript implementation that uses a bytecode interpreter might be developed in the future though.

Executables

When something tries to do too many things it becomes impossible to understand for the average developper. That makes audits and customization harder. Goperscript aims to have a different model. Depending on the features you need, you install one one more executables that try to do one thing well without uncessary bloat (each one providing specific globals to Gophercript).

Documentation

Index

Constants

View Source
const DEFAULT_MAX_STACK_HEIGHT = 5
View Source
const GOPHERSCRIPT_MIMETYPE = "application/gopherscript"
View Source
const HTTP_URL_PATTERN = "^https?:\\/\\/(localhost|(www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,32}\\.[a-zA-Z0-9]{1,6})\\b([-a-zA-Z0-9@:%_+.~#?&//=]{0,100})$"
View Source
const IMPLICIT_KEY_LEN_KEY = "__len"
View Source
const LOOSE_HTTP_EXPR_PATTERN = "^https?:\\/\\/(localhost|(www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,32}\\.[a-zA-Z0-9]{1,6})\\b([-a-zA-Z0-9@:%_+.~#?&//=$]{0,100})$"
View Source
const LOOSE_HTTP_HOST_PATTERN_PATTERN = "^https?:\\/\\/(\\*|(www\\.)?[-a-zA-Z0-9.*]{1,32}\\.[a-zA-Z0-9*]{1,6})(:[0-9]{1,5})?$"
View Source
const MAX_OBJECT_KEY_BYTE_LEN = 64
View Source
const RETURN_1_MODULE_HASH = "SG2a/7YNuwBjsD2OI6bM9jZM4gPcOp9W8g51DrQeyt4="
View Source
const RETURN_GLOBAL_A_MODULE_HASH = "UYvV2gLwfuQ2D91v7PzQ8RMugUTcM0lOysCMqMqXfmg"
View Source
const TOKEN_BUCKET_INTERVAL = 10 * time.Millisecond
View Source
const TRULY_MAX_STACK_HEIGHT = 10

Variables

View Source
var BINARY_OPERATOR_STRINGS = []string{
	"+", "+.", "-", "-.", "*", "*.", "/", "/.", "++", "<", "<.", "<=", "<=", ">", ">.", ">=", ">=.", "==", "!=",
	"in", "not-in", "keyof", ".", "..", "..<", "and", "or",
}
View Source
var CTX_PTR_TYPE = reflect.TypeOf(&Context{})
View Source
var ERROR_INTERFACE_TYPE = reflect.TypeOf((*error)(nil)).Elem()
View Source
var ITERABLE_INTERFACE_TYPE = reflect.TypeOf((*Iterable)(nil)).Elem()
View Source
var KEYWORDS = []string{"if", "else", "require", "for", "assign", "fn", "switch", "match", "import", "sr"}
View Source
var LOOSE_HTTP_EXPR_PATTERN_REGEX = regexp.MustCompile(LOOSE_HTTP_EXPR_PATTERN)
View Source
var LOOSE_HTTP_HOST_PATTERN_REGEX = regexp.MustCompile(LOOSE_HTTP_HOST_PATTERN_PATTERN)
View Source
var MODULE_CACHE = map[string]string{
	RETURN_1_MODULE_HASH:        "return 1",
	RETURN_GLOBAL_A_MODULE_HASH: "return $$a",
}
View Source
var PERMISSION_KIND_STRINGS = []string{"read", "update", "create", "delete", "use", "consume", "provide"}

Functions

func CallFunc

func CallFunc(calleeNode Node, state *State, arguments interface{}, must bool) (interface{}, error)

func Check

func Check(node Node) error

func Eval

func Eval(node Node, state *State) (result interface{}, err error)

func ExtValOf

func ExtValOf(v interface{}, state *State) interface{}

func IsSimpleGopherVal added in v0.1.2

func IsSimpleGopherVal(v interface{}) bool

func MustEval

func MustEval(node Node, state *State) interface{}

func ToReflectVal

func ToReflectVal(v interface{}) reflect.Value

Wraps its argument in a reflect.Value if it is not already wrapped.

func Traverse

func Traverse(v interface{}, fn func(interface{}) (TraversalAction, error), config TraversalConfiguration) (terror error)

Traverse a graph of values starting from v. Only objects & lists are considered source nodes, the other ones are sinks (leafs). A list of encountered source nodes is used to prevent cycling

func UnwrapReflectVal

func UnwrapReflectVal(v interface{}) interface{}

Unwraps the content of a reflect.Value.

func ValOf

func ValOf(v interface{}) interface{}

Unwraps any reflect.Value that wraps a Gopherscript value. Wraps its argument in a reflect.Value if it is not a Gopherscript value.

func Walk

func Walk(node, parent Node, ancestorChain *[]Node, fn func(Node, Node, []Node) error) error

Types

type AbsolutePathExpression

type AbsolutePathExpression struct {
	NodeBase
	Slices []Node
}

type AbsolutePathLiteral

type AbsolutePathLiteral struct {
	NodeBase
	Value string
}

type AbsolutePathPatternLiteral

type AbsolutePathPatternLiteral struct {
	NodeBase
	Value string
}

type Assignment

type Assignment struct {
	NodeBase
	Left  Node
	Right Node
}

type BinaryExpression

type BinaryExpression struct {
	NodeBase
	Operator BinaryOperator
	Left     Node
	Right    Node
}

type BinaryOperator

type BinaryOperator int
const (
	Add BinaryOperator = iota
	AddF
	Sub
	SubF
	Mul
	MulF
	Div
	DivF
	Concat
	LessThan
	LessThanF
	LessOrEqual
	LessOrEqualF
	GreaterThan
	GreaterThanF
	GreaterOrEqual
	GreaterOrEqualF
	Equal
	NotEqual
	In
	NotIn
	Keyof
	Dot //unused, present for symmetry
	Range
	ExclEndRange
	And
	Or
)

func (BinaryOperator) String

func (operator BinaryOperator) String() string

type Block

type Block struct {
	NodeBase
	Statements []Node
}

type BooleanLiteral

type BooleanLiteral struct {
	NodeBase
	Value bool
}

type BreakStatement added in v0.3.0

type BreakStatement struct {
	NodeBase
	Label *IdentifierLiteral //can be nil
}

type ByteCount added in v0.2.0

type ByteCount int

type ByteRate added in v0.2.0

type ByteRate int

type Call

type Call struct {
	NodeBase
	Callee    Node
	Arguments []Node
	Must      bool
}

type Case

type Case struct {
	NodeBase
	Value Node
	Block *Block
}

type CommandPermission added in v0.1.2

type CommandPermission struct {
	CommandName         string
	SubcommandNameChain []string //can be empty
}

func (CommandPermission) Includes added in v0.1.2

func (perm CommandPermission) Includes(otherPerm Permission) bool

func (CommandPermission) Kind added in v0.1.2

func (perm CommandPermission) Kind() PermissionKind

func (CommandPermission) String added in v0.1.2

func (perm CommandPermission) String() string

type Context

type Context struct {
	// contains filtered or unexported fields
}

func NewContext

func NewContext(permissions []Permission, forbiddenPermissions []Permission, limitations []Limitation) *Context

func (*Context) CheckHasPermission

func (ctx *Context) CheckHasPermission(perm Permission) error

func (*Context) GetRate added in v0.2.0

func (ctx *Context) GetRate(name string) ByteRate

func (*Context) HasPermission

func (ctx *Context) HasPermission(perm Permission) bool

func (*Context) NewWith added in v0.3.1

func (ctx *Context) NewWith(additionalPerms []Permission) (*Context, error)

Creates a new Context with additional permissions

func (*Context) NewWithout added in v0.3.1

func (ctx *Context) NewWithout(removedPerms []Permission) (*Context, error)

Creates a new Context with the permissions passed as argument removed.

func (*Context) Take added in v0.2.0

func (ctx *Context) Take(name string, count int64)

type ContextConfig added in v0.3.1

type ContextConfig struct {
	// contains filtered or unexported fields
}

type ContextlessCallPermission added in v0.3.1

type ContextlessCallPermission struct {
	FuncMethodName   string
	ReceiverTypeName string
}

func (ContextlessCallPermission) Includes added in v0.3.1

func (perm ContextlessCallPermission) Includes(otherPerm Permission) bool

func (ContextlessCallPermission) Kind added in v0.3.1

func (ContextlessCallPermission) String added in v0.3.1

func (perm ContextlessCallPermission) String() string

type ContinueStatement added in v0.3.0

type ContinueStatement struct {
	NodeBase
	Label *IdentifierLiteral //can be nil
}

type EmbeddedModule

type EmbeddedModule struct {
	NodeBase
	Requirements *Requirements
	Statements   []Node
}

type ExternalValue

type ExternalValue struct {
	// contains filtered or unexported fields
}

type FilesystemPermission

type FilesystemPermission struct {
	Kind_  PermissionKind
	Entity interface{}
}

func (FilesystemPermission) Includes

func (perm FilesystemPermission) Includes(otherPerm Permission) bool

func (FilesystemPermission) Kind

func (FilesystemPermission) String

func (perm FilesystemPermission) String() string

type FloatLiteral

type FloatLiteral struct {
	NodeBase
	Raw   string
	Value float64
}

type ForStatement

type ForStatement struct {
	NodeBase
	KeyIndexIdent  *IdentifierLiteral //can be nil
	ValueElemIdent *IdentifierLiteral //can be nil
	Body           *Block
	IteratedValue  Node
}

type Func

type Func Node

type FunctionDeclaration

type FunctionDeclaration struct {
	NodeBase
	Function *FunctionExpression
	Name     *IdentifierLiteral
}

type FunctionExpression

type FunctionExpression struct {
	NodeBase
	Parameters   []FunctionParameter
	Body         *Block
	Requirements *Requirements
}

type FunctionParameter

type FunctionParameter struct {
	Var *Variable
}

type GlobalConstantDeclarations

type GlobalConstantDeclarations struct {
	NodeBase
	NamesValues [][2]Node
}

type GlobalVarPermission

type GlobalVarPermission struct {
	Kind_ PermissionKind
	Name  string //"*" means any
}

func (GlobalVarPermission) Includes

func (perm GlobalVarPermission) Includes(otherPerm Permission) bool

func (GlobalVarPermission) Kind

func (perm GlobalVarPermission) Kind() PermissionKind

func (GlobalVarPermission) String

func (perm GlobalVarPermission) String() string

type GlobalVariable

type GlobalVariable struct {
	NodeBase
	Name string
}

type HTTPHost

type HTTPHost string

type HTTPHostLiteral

type HTTPHostLiteral struct {
	NodeBase
	Value string
}

type HTTPHostPattern

type HTTPHostPattern string

func (HTTPHostPattern) IsMatcherFor

func (patt HTTPHostPattern) IsMatcherFor(v interface{}) bool

type HTTPHostPatternLiteral

type HTTPHostPatternLiteral struct {
	NodeBase
	Value string
}

type HttpPermission

type HttpPermission struct {
	Kind_  PermissionKind
	Entity interface{}
}

func (HttpPermission) Includes

func (perm HttpPermission) Includes(otherPerm Permission) bool

func (HttpPermission) Kind

func (perm HttpPermission) Kind() PermissionKind

func (HttpPermission) String

func (perm HttpPermission) String() string

type Identifier

type Identifier string

type IdentifierLiteral

type IdentifierLiteral struct {
	NodeBase
	Name string
}

type IdentifierMemberExpression

type IdentifierMemberExpression struct {
	NodeBase
	Left          Node
	PropertyNames []*IdentifierLiteral
}

type IfStatement

type IfStatement struct {
	NodeBase
	Test       Node
	Consequent *Block
	Alternate  *Block //can be nil
}

type ImportStatement

type ImportStatement struct {
	NodeBase
	Identifier         *IdentifierLiteral
	URL                *URLLiteral
	ValidationString   *StringLiteral
	ArgumentObject     *ObjectLiteral
	GrantedPermissions *ObjectLiteral
}

type IndexExpression

type IndexExpression struct {
	NodeBase
	Indexed Node
	Index   Node
}

type IntLiteral

type IntLiteral struct {
	NodeBase
	Raw   string
	Value int
}

type IntRange

type IntRange struct {
	Start int
	End   int
	Step  int
	// contains filtered or unexported fields
}

func (IntRange) Iterator

func (r IntRange) Iterator() Iterator

type IntRangeIterator

type IntRangeIterator struct {
	// contains filtered or unexported fields
}

func (*IntRangeIterator) GetNext

func (it *IntRangeIterator) GetNext() interface{}

func (IntRangeIterator) HasNext

func (it IntRangeIterator) HasNext() bool

type Iterable

type Iterable interface {
	Iterator() Iterator
}

type IterationChange added in v0.3.0

type IterationChange int
const (
	NoIterationChange IterationChange = iota
	BreakIteration
	ContinueIteration
)

type Iterator

type Iterator interface {
	HasNext() bool
	GetNext() interface{}
}

type JSONstring

type JSONstring string

special string types

type KeyList

type KeyList []string

type KeyListExpression

type KeyListExpression struct {
	NodeBase
	Keys []*IdentifierLiteral
}

type LazyExpression

type LazyExpression struct {
	NodeBase
	Expression Node
}

type Limitation added in v0.2.0

type Limitation struct {
	Name string
	Rate ByteRate
}

type Limiter added in v0.2.0

type Limiter struct {
	// contains filtered or unexported fields
}

type LineCount

type LineCount int

type List

type List []interface{}

type ListLiteral

type ListLiteral struct {
	NodeBase
	Elements []Node
}

type MatchStatement

type MatchStatement struct {
	NodeBase
	Discriminant Node
	Cases        []*Case
}

type Matcher

type Matcher interface {
	IsMatcherFor(interface{}) bool
}

type MemberExpression

type MemberExpression struct {
	NodeBase
	Left         Node
	PropertyName *IdentifierLiteral
}

type Module

type Module struct {
	NodeBase
	GlobalConstantDeclarations *GlobalConstantDeclarations //nil if no const declarations at the top of the module
	Requirements               *Requirements               //nil if no require at the top of the module
	Statements                 []Node
}

func MustParseModule

func MustParseModule(str string) (result *Module)

func ParseAndCheckModule

func ParseAndCheckModule(s string, fpath string) (*Module, error)

func ParseModule

func ParseModule(str string, fpath string) (result *Module, resultErr error)

type MultiAssignment

type MultiAssignment struct {
	NodeBase
	Variables []Node
	Right     Node
}

type NilLiteral

type NilLiteral struct {
	NodeBase
}

type Node

type Node interface {
	Base() NodeBase
}

all node types embed NodeBase, NodeBase implements the Node interface

type NodeBase

type NodeBase struct {
	Span NodeSpan
}

func (NodeBase) Base

func (base NodeBase) Base() NodeBase

func (NodeBase) IncludedIn added in v0.2.0

func (base NodeBase) IncludedIn(node Node) bool

type NodeCategory added in v0.2.0

type NodeCategory int
const (
	UnspecifiedCategory NodeCategory = iota
	URLlike
	Pathlike
	IdentLike
	KnownType
)

type NodeSpan

type NodeSpan struct {
	Start int
	End   int
}

type NotAllowedError

type NotAllowedError struct {
	Permission Permission
	Message    string
}

func (NotAllowedError) Error

func (err NotAllowedError) Error() string

type Object

type Object map[string]interface{}

int, float64, string, bool, reflect.Value

type ObjectLiteral

type ObjectLiteral struct {
	NodeBase
	Properties []ObjectProperty
}

func (ObjectLiteral) PermissionsLimitations added in v0.2.0

func (objLit ObjectLiteral) PermissionsLimitations(
	globalConsts *GlobalConstantDeclarations,
	runningState *State,
	handleCustomType func(kind PermissionKind, name string) ([]Permission, bool, error),
) ([]Permission, []Limitation)

type ObjectProperty

type ObjectProperty struct {
	NodeBase
	Key   Node //can be nil (implicit key)
	Value Node
}

func (ObjectProperty) HasImplicitKey added in v0.1.2

func (prop ObjectProperty) HasImplicitKey() bool

func (ObjectProperty) Name

func (prop ObjectProperty) Name() string

type ParsingError

type ParsingError struct {
	Message string
	Index   int

	NodeStartIndex int //< 0 if not specified
	NodeCategory   NodeCategory
	NodeType       Node //not nil if .NodeCategory is KnownType
}

func (ParsingError) Error

func (err ParsingError) Error() string

type Path

type Path string

func (Path) IsDirPath

func (pth Path) IsDirPath() bool

func (Path) ToAbs

func (pth Path) ToAbs() Path

type PathPattern

type PathPattern string

func (PathPattern) IsMatcherFor

func (patt PathPattern) IsMatcherFor(v interface{}) bool

func (PathPattern) IsPrefixPattern

func (patt PathPattern) IsPrefixPattern() bool

func (PathPattern) Prefix

func (patt PathPattern) Prefix() string

func (PathPattern) ToAbs

func (patt PathPattern) ToAbs() PathPattern

type PathSlice

type PathSlice struct {
	NodeBase
	Value string
}

type Permission

type Permission interface {
	Kind() PermissionKind
	Includes(Permission) bool
	String() string
}

type PermissionKind

type PermissionKind int
const (
	ReadPerm PermissionKind = iota
	UpdatePerm
	CreatePerm
	DeletePerm
	UsePerm
	ConsumePerm
	ProvidePerm
)

func PermissionKindFromString

func PermissionKindFromString(s string) (PermissionKind, bool)

func (PermissionKind) String

func (kind PermissionKind) String() string

type QuantityLiteral

type QuantityLiteral struct {
	NodeBase
	Raw   string
	Value float64
	Unit  string
}

type QuantityRange

type QuantityRange struct {
	Start interface{}
	End   interface{}
	// contains filtered or unexported fields
}

type RateLiteral added in v0.2.0

type RateLiteral struct {
	NodeBase
	Quantity *QuantityLiteral
	Unit     *IdentifierLiteral
}

type RelativePathExpression

type RelativePathExpression struct {
	NodeBase
	Slices []Node
}

type RelativePathLiteral

type RelativePathLiteral struct {
	NodeBase
	Value string
}

type RelativePathPatternLiteral

type RelativePathPatternLiteral struct {
	NodeBase
	Value string
}

type Requirements

type Requirements struct {
	Object *ObjectLiteral
}

type ReturnStatement

type ReturnStatement struct {
	NodeBase
	Expr Node
}

type Routine

type Routine struct {
	// contains filtered or unexported fields
}

func (*Routine) WaitResult

func (routine *Routine) WaitResult(ctx *Context) (interface{}, error)

type RoutineGroup

type RoutineGroup struct {
	// contains filtered or unexported fields
}

func (*RoutineGroup) WaitAllResults

func (group *RoutineGroup) WaitAllResults(ctx *Context) (interface{}, error)

type RoutinePermission

type RoutinePermission struct {
	Kind_ PermissionKind
}

func (RoutinePermission) Includes

func (perm RoutinePermission) Includes(otherPerm Permission) bool

func (RoutinePermission) Kind

func (perm RoutinePermission) Kind() PermissionKind

func (RoutinePermission) String

func (perm RoutinePermission) String() string

type SliceExpression

type SliceExpression struct {
	NodeBase
	Indexed    Node
	StartIndex Node //can be nil
	EndIndex   Node //can be nil
}

type SpawnExpression

type SpawnExpression struct {
	NodeBase
	GroupIdent         *IdentifierLiteral //can be nil
	Globals            Node
	ExprOrVar          Node
	GrantedPermissions *ObjectLiteral //nil if no "allow ...." in the spawn expression
}

type StackPermission

type StackPermission struct {
	// contains filtered or unexported fields
}

func (StackPermission) Includes

func (perm StackPermission) Includes(otherPerm Permission) bool

func (StackPermission) Kind

func (perm StackPermission) Kind() PermissionKind

func (StackPermission) String

func (perm StackPermission) String() string

type State

type State struct {
	ScopeStack  []map[string]interface{}
	ReturnValue *interface{}
	IterationChange
	// contains filtered or unexported fields
}

func NewState

func NewState(ctx *Context, args ...map[string]interface{}) *State

func (State) CurrentScope

func (state State) CurrentScope() map[string]interface{}

func (State) GlobalScope

func (state State) GlobalScope() map[string]interface{}

func (*State) PopScope

func (state *State) PopScope()

func (*State) PushScope

func (state *State) PushScope()

type Statement

type Statement interface {
	Node
}

type StringLiteral

type StringLiteral struct {
	NodeBase
	Raw   string
	Value string
}

type SwitchStatement

type SwitchStatement struct {
	NodeBase
	Discriminant Node
	Cases        []*Case
}

type TokenBucket added in v0.2.0

type TokenBucket struct {
	// contains filtered or unexported fields
}

TokenBucket represents a token bucket (https://en.wikipedia.org/wiki/Token_bucket) which based on multi goroutines, and is safe to use under concurrency environments.

func (*TokenBucket) Availible added in v0.2.0

func (tb *TokenBucket) Availible() int64

Availible returns how many tokens are availible in the bucket.

func (*TokenBucket) Capability added in v0.2.0

func (tb *TokenBucket) Capability() int64

Capability returns the capability of this token bucket.

func (*TokenBucket) Destory added in v0.2.0

func (tb *TokenBucket) Destory()

Destory destorys the token bucket and stop the inner channels.

func (*TokenBucket) Take added in v0.2.0

func (tb *TokenBucket) Take(count int64)

Take tasks specified count tokens from the bucket, if there are not enough tokens in the bucket, it will keep waiting until count tokens are availible and then take them.

func (*TokenBucket) TakeMaxDuration added in v0.2.0

func (tb *TokenBucket) TakeMaxDuration(count int64, max time.Duration) bool

TakeMaxDuration tasks specified count tokens from the bucket, if there are not enough tokens in the bucket, it will keep waiting until count tokens are availible and then take them or just return false when reach the given max duration.

func (*TokenBucket) TryTake added in v0.2.0

func (tb *TokenBucket) TryTake(count int64) bool

TryTake trys to task specified count tokens from the bucket. if there are not enough tokens in the bucket, it will return false.

func (*TokenBucket) Wait added in v0.2.0

func (tb *TokenBucket) Wait(count int64)

Wait will keep waiting until count tokens are availible in the bucket.

func (*TokenBucket) WaitMaxDuration added in v0.2.0

func (tb *TokenBucket) WaitMaxDuration(count int64, max time.Duration) bool

WaitMaxDuration will keep waiting until count tokens are availible in the bucket or just return false when reach the given max duration.

type TraversalAction

type TraversalAction int
const (
	Continue TraversalAction = iota
	Prune
	StopTraversal
)

type TraversalConfiguration

type TraversalConfiguration struct {
	MaxDepth int
}

type TraversalOrder

type TraversalOrder int

type URL

type URL string

type URLExpression

type URLExpression struct {
	NodeBase
	Raw      string
	HostPart string
	Path     *AbsolutePathExpression
}

type URLLiteral

type URLLiteral struct {
	NodeBase
	Value string
}

type URLPattern

type URLPattern string

func (URLPattern) IsMatcherFor

func (patt URLPattern) IsMatcherFor(v interface{}) bool

func (URLPattern) Prefix

func (patt URLPattern) Prefix() string

type URLPatternLiteral

type URLPatternLiteral struct {
	NodeBase
	Value string
}

type UpperBoundRangeExpression

type UpperBoundRangeExpression struct {
	NodeBase
	UpperBound Node
}

type Variable

type Variable struct {
	NodeBase
	Name string
}

Directories

Path Synopsis
cmd
gos command

Jump to

Keyboard shortcuts

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