interpreter

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DIRECTORTYPE_RANDOM   = "random"
	DIRECTORTYPE_FALLBACK = "fallback"
	DIRECTORTYPE_HASH     = "hash"
	DIRECTORTYPE_CLIENT   = "client"
	DIRECTORTYPE_CHASH    = "chash"
	DIRECTORTYPE_SHIELD   = "shield"
)
View Source
const HTTPS_SCHEME = "https"

Variables

View Source
var (
	ErrQuorumWeightNotReached = errors.New("Quorum weight not reached")
	ErrAllBackendsFailed      = errors.New("All backend failed")
)

Functions

This section is empty.

Types

type DebugState

type DebugState int
const (
	DebugPass DebugState = iota
	DebugStepIn
	DebugStepOver
	DebugStepOut
)

type Debugger

type Debugger interface {
	Run(ast.Node) DebugState
	Message(string)
}

type DefaultDebugger

type DefaultDebugger struct{}

Default debugger, simply output message to stdout

func (DefaultDebugger) Message

func (d DefaultDebugger) Message(msg string)

func (DefaultDebugger) Run

func (d DefaultDebugger) Run(node ast.Node) DebugState

type Interpreter

type Interpreter struct {
	Debugger      Debugger
	IdentResolver func(v string) value.Value

	TestingState State
	// contains filtered or unexported fields
}

func New

func New(options ...context.Option) *Interpreter

func (*Interpreter) ConsoleProcessInit added in v1.6.0

func (i *Interpreter) ConsoleProcessInit() error

func (*Interpreter) IdentValue

func (i *Interpreter) IdentValue(val string, withCondition bool) (value.Value, error)

func (*Interpreter) ProcessAddStatement

func (i *Interpreter) ProcessAddStatement(stmt *ast.AddStatement) error

func (*Interpreter) ProcessBackends added in v1.2.0

func (i *Interpreter) ProcessBackends(statements []ast.Statement) error

func (*Interpreter) ProcessBlockStatement

func (i *Interpreter) ProcessBlockStatement(
	statements []ast.Statement,
	ds DebugState,

	isReturnAsValue bool,
) (value.Value, State, DebugState, error)

nolint: gocognit

func (*Interpreter) ProcessCallStatement

func (i *Interpreter) ProcessCallStatement(stmt *ast.CallStatement, ds DebugState) (State, error)

func (*Interpreter) ProcessCaseStatement added in v1.4.0

func (i *Interpreter) ProcessCaseStatement(
	stmt *ast.SwitchStatement,
	offset int,
	control value.Value,
	isFallthrough bool,
	ds DebugState,
	isReturnAsValue bool,
) (value.Value, State, bool, error)

func (*Interpreter) ProcessDeclarations

func (i *Interpreter) ProcessDeclarations(statements []ast.Statement) error

func (*Interpreter) ProcessDeclareStatement

func (i *Interpreter) ProcessDeclareStatement(stmt *ast.DeclareStatement) error

func (*Interpreter) ProcessDeliver

func (i *Interpreter) ProcessDeliver() error

func (*Interpreter) ProcessError

func (i *Interpreter) ProcessError() error

func (*Interpreter) ProcessErrorStatement

func (i *Interpreter) ProcessErrorStatement(stmt *ast.ErrorStatement) error

func (*Interpreter) ProcessEsiStatement

func (i *Interpreter) ProcessEsiStatement(stmt *ast.EsiStatement) error

func (*Interpreter) ProcessExpression

func (i *Interpreter) ProcessExpression(exp ast.Expression, withCondition bool) (value.Value, error)

Evaluate expression withCondition boolean is special flag for evaluating expression, used for if condition, parenthesis wrapped expression. On if condition, prefix expression could use "!" prefix operator for null value.

For example:

withCondition: true  -> if (!req.http.Foo) { ... } // Valid, req.http.Foo is nullable string but can be inverse as false
withCondition: false -> set var.bool = (!req.http.Foo); // Complicated but valid, "!" prefix operator could  use for right expression
withCondition: false -> set var.bool = !req.http.Foo;   // Invalid, bare "!" prefix operator could not use for right expression

func (*Interpreter) ProcessExpressionReturnStatement added in v1.4.0

func (i *Interpreter) ProcessExpressionReturnStatement(stmt *ast.ReturnStatement) (value.Value, State, error)

func (*Interpreter) ProcessFetch

func (i *Interpreter) ProcessFetch() error

func (*Interpreter) ProcessFunctionCallExpression

func (i *Interpreter) ProcessFunctionCallExpression(exp *ast.FunctionCallExpression, withCondition bool) (value.Value, error)

func (*Interpreter) ProcessFunctionCallStatement

func (i *Interpreter) ProcessFunctionCallStatement(stmt *ast.FunctionCallStatement, ds DebugState) (State, error)

func (*Interpreter) ProcessFunctionSubroutine

func (i *Interpreter) ProcessFunctionSubroutine(sub *ast.SubroutineDeclaration, ds DebugState) (value.Value, State, error)

nolint: gocognit

func (*Interpreter) ProcessGroupedExpression

func (i *Interpreter) ProcessGroupedExpression(exp *ast.GroupedExpression) (value.Value, error)

func (*Interpreter) ProcessHash

func (i *Interpreter) ProcessHash() error

func (*Interpreter) ProcessHit

func (i *Interpreter) ProcessHit() error

func (*Interpreter) ProcessIfExpression

func (i *Interpreter) ProcessIfExpression(exp *ast.IfExpression) (value.Value, error)

func (*Interpreter) ProcessIfStatement

func (i *Interpreter) ProcessIfStatement(
	stmt *ast.IfStatement,
	ds DebugState,
	isReturnAsValue bool,
) (value.Value, State, error)

nolint:gocognit

func (*Interpreter) ProcessInfixExpression

func (i *Interpreter) ProcessInfixExpression(exp *ast.InfixExpression, withCondition bool) (value.Value, error)

func (*Interpreter) ProcessInit

func (i *Interpreter) ProcessInit(r *http.Request) error

func (*Interpreter) ProcessLog

func (i *Interpreter) ProcessLog() error

func (*Interpreter) ProcessLogStatement

func (i *Interpreter) ProcessLogStatement(stmt *ast.LogStatement) error

func (*Interpreter) ProcessMiss

func (i *Interpreter) ProcessMiss() error

func (*Interpreter) ProcessPass

func (i *Interpreter) ProcessPass() error

func (*Interpreter) ProcessPostfixExpression added in v1.5.0

func (i *Interpreter) ProcessPostfixExpression(exp *ast.PostfixExpression) (value.Value, error)

func (*Interpreter) ProcessPrefixExpression

func (i *Interpreter) ProcessPrefixExpression(exp *ast.PrefixExpression, withCondition bool) (value.Value, error)

func (*Interpreter) ProcessRecv

func (i *Interpreter) ProcessRecv() error

func (*Interpreter) ProcessRemoveStatement

func (i *Interpreter) ProcessRemoveStatement(stmt *ast.RemoveStatement) error

func (*Interpreter) ProcessReturnStatement

func (i *Interpreter) ProcessReturnStatement(stmt *ast.ReturnStatement) State

func (*Interpreter) ProcessSetStatement

func (i *Interpreter) ProcessSetStatement(stmt *ast.SetStatement) error

func (*Interpreter) ProcessSubroutine

func (i *Interpreter) ProcessSubroutine(sub *ast.SubroutineDeclaration, ds DebugState) (State, error)

func (*Interpreter) ProcessSwitchStatement added in v1.4.0

func (i *Interpreter) ProcessSwitchStatement(
	stmt *ast.SwitchStatement,
	ds DebugState,
	isReturnAsValue bool,
) (value.Value, State, error)

func (*Interpreter) ProcessSyntheticBase64Statement

func (i *Interpreter) ProcessSyntheticBase64Statement(stmt *ast.SyntheticBase64Statement) error

func (*Interpreter) ProcessSyntheticStatement

func (i *Interpreter) ProcessSyntheticStatement(stmt *ast.SyntheticStatement) error

func (*Interpreter) ProcessTestSubroutine

func (i *Interpreter) ProcessTestSubroutine(scope context.Scope, sub *ast.SubroutineDeclaration) error

func (*Interpreter) ProcessUnsetStatement

func (i *Interpreter) ProcessUnsetStatement(stmt *ast.UnsetStatement) error

func (*Interpreter) ServeHTTP

func (i *Interpreter) ServeHTTP(w http.ResponseWriter, r *http.Request)

Implements http.Handler

func (*Interpreter) SetScope

func (i *Interpreter) SetScope(scope context.Scope)

func (*Interpreter) TestProcessInit

func (i *Interpreter) TestProcessInit(r *http.Request) error

type State

type State string
const (
	NONE           State = ""
	LOOKUP         State = "lookup"
	PASS           State = "pass"
	HASH           State = "hash"
	ERROR          State = "error"
	RESTART        State = "restart"
	DELIVER        State = "deliver"
	FETCH          State = "fetch"
	DELIVER_STALE  State = "deliver_stale"
	LOG            State = "log"
	END            State = "end"
	INTERNAL_ERROR State = "_internal_error_"
	BARE_RETURN    State = "_bare_return_"
)

func StateFromString added in v1.3.0

func StateFromString(s string) State

func (State) String

func (s State) String() string

Directories

Path Synopsis
Falco's interpreter cacheing is simply in-memory
Falco's interpreter cacheing is simply in-memory

Jump to

Keyboard shortcuts

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