Documentation
¶
Index ¶
- Constants
- Variables
- func CallFunc(calleeNode Node, state *State, arguments interface{}, must bool) (interface{}, error)
- func Check(node Node) error
- func Eval(node Node, state *State) (result interface{}, err error)
- func ExtValOf(v interface{}, state *State) interface{}
- func IsSimpleGopherVal(v interface{}) bool
- func MustEval(node Node, state *State) interface{}
- func ToReflectVal(v interface{}) reflect.Value
- func Traverse(v interface{}, fn func(interface{}) (TraversalAction, error), ...) (terror error)
- func UnwrapReflectVal(v interface{}) interface{}
- func ValOf(v interface{}) interface{}
- func Walk(node, parent Node, ancestorChain *[]Node, fn func(Node, Node, []Node) error) error
- type AbsolutePathExpression
- type AbsolutePathLiteral
- type AbsolutePathPatternLiteral
- type Assignment
- type BinaryExpression
- type BinaryOperator
- type Block
- type BooleanLiteral
- type BreakStatement
- type ByteCount
- type ByteRate
- type Call
- type Case
- type CommandPermission
- type Context
- func (ctx *Context) CheckHasPermission(perm Permission) error
- func (ctx *Context) GetRate(name string) ByteRate
- func (ctx *Context) HasPermission(perm Permission) bool
- func (ctx *Context) NewWith(additionalPerms []Permission) (*Context, error)
- func (ctx *Context) NewWithout(removedPerms []Permission) (*Context, error)
- func (ctx *Context) Take(name string, count int64)
- type ContextConfig
- type ContextlessCallPermission
- type ContinueStatement
- type EmbeddedModule
- type ExternalValue
- type FilesystemPermission
- type FloatLiteral
- type ForStatement
- type Func
- type FunctionDeclaration
- type FunctionExpression
- type FunctionParameter
- type GlobalConstantDeclarations
- type GlobalVarPermission
- type GlobalVariable
- type HTTPHost
- type HTTPHostLiteral
- type HTTPHostPattern
- type HTTPHostPatternLiteral
- type HttpPermission
- type Identifier
- type IdentifierLiteral
- type IdentifierMemberExpression
- type IfStatement
- type ImportStatement
- type IndexExpression
- type IntLiteral
- type IntRange
- type IntRangeIterator
- type Iterable
- type IterationChange
- type Iterator
- type JSONstring
- type KeyList
- type KeyListExpression
- type LazyExpression
- type Limitation
- type Limiter
- type LineCount
- type List
- type ListLiteral
- type MatchStatement
- type Matcher
- type MemberExpression
- type Module
- type MultiAssignment
- type NilLiteral
- type Node
- type NodeBase
- type NodeCategory
- type NodeSpan
- type NotAllowedError
- type Object
- type ObjectLiteral
- type ObjectProperty
- type ParsingError
- type Path
- type PathPattern
- type PathSlice
- type Permission
- type PermissionKind
- type QuantityLiteral
- type QuantityRange
- type RateLiteral
- type RelativePathExpression
- type RelativePathLiteral
- type RelativePathPatternLiteral
- type Requirements
- type ReturnStatement
- type Routine
- type RoutineGroup
- type RoutinePermission
- type SliceExpression
- type SpawnExpression
- type StackPermission
- type State
- type Statement
- type StringLiteral
- type SwitchStatement
- type TokenBucket
- func (tb *TokenBucket) Availible() int64
- func (tb *TokenBucket) Capability() int64
- func (tb *TokenBucket) Destory()
- func (tb *TokenBucket) Take(count int64)
- func (tb *TokenBucket) TakeMaxDuration(count int64, max time.Duration) bool
- func (tb *TokenBucket) TryTake(count int64) bool
- func (tb *TokenBucket) Wait(count int64)
- func (tb *TokenBucket) WaitMaxDuration(count int64, max time.Duration) bool
- type TraversalAction
- type TraversalConfiguration
- type TraversalOrder
- type URL
- type URLExpression
- type URLLiteral
- type URLPattern
- type URLPatternLiteral
- type UpperBoundRangeExpression
- type Variable
Constants ¶
const DEFAULT_MAX_STACK_HEIGHT = 5
const GOPHERSCRIPT_MIMETYPE = "application/gopherscript"
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})$"
const IMPLICIT_KEY_LEN_KEY = "__len"
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})$"
const LOOSE_HTTP_HOST_PATTERN_PATTERN = "^https?:\\/\\/(\\*|(www\\.)?[-a-zA-Z0-9.*]{1,32}\\.[a-zA-Z0-9*]{1,6})(:[0-9]{1,5})?$"
const MAX_OBJECT_KEY_BYTE_LEN = 64
const RETURN_1_MODULE_HASH = "SG2a/7YNuwBjsD2OI6bM9jZM4gPcOp9W8g51DrQeyt4="
const RETURN_GLOBAL_A_MODULE_HASH = "UYvV2gLwfuQ2D91v7PzQ8RMugUTcM0lOysCMqMqXfmg"
const TOKEN_BUCKET_INTERVAL = 10 * time.Millisecond
const TRULY_MAX_STACK_HEIGHT = 10
Variables ¶
var BINARY_OPERATOR_STRINGS = []string{
"+", "+.", "-", "-.", "*", "*.", "/", "/.", "++", "<", "<.", "<=", "<=", ">", ">.", ">=", ">=.", "==", "!=",
"in", "not-in", "keyof", ".", "..", "..<", "and", "or",
}
var CTX_PTR_TYPE = reflect.TypeOf(&Context{})
var ERROR_INTERFACE_TYPE = reflect.TypeOf((*error)(nil)).Elem()
var HTTP_URL_REGEX = regexp.MustCompile(HTTP_URL_PATTERN)
var ITERABLE_INTERFACE_TYPE = reflect.TypeOf((*Iterable)(nil)).Elem()
var KEYWORDS = []string{"if", "else", "require", "for", "assign", "fn", "switch", "match", "import", "sr"}
var LOOSE_HTTP_EXPR_PATTERN_REGEX = regexp.MustCompile(LOOSE_HTTP_EXPR_PATTERN)
var LOOSE_HTTP_HOST_PATTERN_REGEX = regexp.MustCompile(LOOSE_HTTP_HOST_PATTERN_PATTERN)
var MODULE_CACHE = map[string]string{ RETURN_1_MODULE_HASH: "return 1", RETURN_GLOBAL_A_MODULE_HASH: "return $$a", }
var PERMISSION_KIND_STRINGS = []string{"read", "update", "create", "delete", "use", "consume", "provide"}
Functions ¶
func IsSimpleGopherVal ¶ added in v0.1.2
func IsSimpleGopherVal(v interface{}) bool
func ToReflectVal ¶
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.
Types ¶
type AbsolutePathExpression ¶
type AbsolutePathLiteral ¶
type Assignment ¶
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 BooleanLiteral ¶
type BreakStatement ¶ added in v0.3.0
type BreakStatement struct {
NodeBase
Label *IdentifierLiteral //can be nil
}
type CommandPermission ¶ added in v0.1.2
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) 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.
type ContextConfig ¶ added in v0.3.1
type ContextConfig struct {
// contains filtered or unexported fields
}
type ContextlessCallPermission ¶ added in v0.3.1
func (ContextlessCallPermission) Includes ¶ added in v0.3.1
func (perm ContextlessCallPermission) Includes(otherPerm Permission) bool
func (ContextlessCallPermission) Kind ¶ added in v0.3.1
func (perm ContextlessCallPermission) Kind() PermissionKind
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 (perm FilesystemPermission) Kind() PermissionKind
func (FilesystemPermission) String ¶
func (perm FilesystemPermission) String() string
type FloatLiteral ¶
type ForStatement ¶
type ForStatement struct {
NodeBase
KeyIndexIdent *IdentifierLiteral //can be nil
ValueElemIdent *IdentifierLiteral //can be nil
Body *Block
IteratedValue 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 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 HTTPHostLiteral ¶
type HTTPHostPattern ¶
type HTTPHostPattern string
func (HTTPHostPattern) IsMatcherFor ¶
func (patt HTTPHostPattern) IsMatcherFor(v interface{}) bool
type HTTPHostPatternLiteral ¶
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 IdentifierMemberExpression ¶
type IdentifierMemberExpression struct {
NodeBase
Left Node
PropertyNames []*IdentifierLiteral
}
type IfStatement ¶
type ImportStatement ¶
type ImportStatement struct {
NodeBase
Identifier *IdentifierLiteral
URL *URLLiteral
ValidationString *StringLiteral
ArgumentObject *ObjectLiteral
GrantedPermissions *ObjectLiteral
}
type IndexExpression ¶
type IntLiteral ¶
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 IterationChange ¶ added in v0.3.0
type IterationChange int
const ( NoIterationChange IterationChange = iota BreakIteration ContinueIteration )
type KeyListExpression ¶
type KeyListExpression struct {
NodeBase
Keys []*IdentifierLiteral
}
type LazyExpression ¶
type Limitation ¶ added in v0.2.0
type ListLiteral ¶
type MatchStatement ¶
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 ¶
type MultiAssignment ¶
type NilLiteral ¶
type NilLiteral struct {
NodeBase
}
type Node ¶
type Node interface {
Base() NodeBase
}
all node types embed NodeBase, NodeBase implements the Node interface
type NodeCategory ¶ added in v0.2.0
type NodeCategory int
const ( UnspecifiedCategory NodeCategory = iota URLlike Pathlike IdentLike KnownType )
type NotAllowedError ¶
type NotAllowedError struct {
Permission Permission
Message string
}
func (NotAllowedError) Error ¶
func (err NotAllowedError) Error() string
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 ¶
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 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 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 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 RelativePathLiteral ¶
type Requirements ¶
type Requirements struct {
Object *ObjectLiteral
}
type ReturnStatement ¶
type Routine ¶
type Routine struct {
// contains filtered or unexported fields
}
func (*Routine) WaitResult ¶
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 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 (State) CurrentScope ¶
func (State) GlobalScope ¶
type StringLiteral ¶
type SwitchStatement ¶
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 URLExpression ¶
type URLExpression struct {
NodeBase
Raw string
HostPart string
Path *AbsolutePathExpression
}
type URLLiteral ¶
type URLPattern ¶
type URLPattern string
func (URLPattern) IsMatcherFor ¶
func (patt URLPattern) IsMatcherFor(v interface{}) bool
func (URLPattern) Prefix ¶
func (patt URLPattern) Prefix() string



