Documentation ¶
Index ¶
- Constants
- Variables
- func MakeFileLibraryProvider(dir string) func(*Interpreter, string) (string, error)
- func WithMaxRuntimes(n int) func(*Interpreter) error
- type Config
- type Filter
- func (f *Filter) Config() interface{}
- func (f *Filter) EventErrorCount() int
- func (f *Filter) EventErrorVelocity() int
- func (f *Filter) EventFilterCount() int
- func (f *Filter) EventFilterVelocity() int
- func (f *Filter) EventSuccessCount() int
- func (f *Filter) EventSuccessVelocity() int
- func (f *Filter) EventTs() int64
- func (f *Filter) Filter(evt event.Event) []event.Event
- func (f *Filter) Hash() string
- func (f *Filter) Name() string
- func (f *Filter) Plugin() string
- func (f *Filter) Tenant() tenant.Id
- type Interpreter
- func (interpreter *Interpreter) Compile(code string) (interface{}, error)
- func (interpreter *Interpreter) CompileLibrary(name, src string) (interface{}, error)
- func (interpreter *Interpreter) Exec(evt event.Event, code string) ([]event.Event, error)
- func (interpreter *Interpreter) ProvideLibrary(name string) (string, error)
- type Program
- type Runtime
Constants ¶
const (
RuntimeTTL = 5 * time.Minute
)
Variables ¶
var ( // InterruptedMessage is the string value of Interrupted. InterruptedMessage = "RuntimeError: timeout" // Interrupted is returned by Exec if the execution is // interrupted. Interrupted = errors.New(InterruptedMessage) )
var DefaultConfig = Config{Source: ""}
var DefaultLibraryProvider = MakeFileLibraryProvider(".")
Functions ¶
func MakeFileLibraryProvider ¶
func MakeFileLibraryProvider(dir string) func(*Interpreter, string) (string, error)
DefaultProvider is a method that Provide will use if the interpreter's Provider is nil.
This method barely supports names that are URLs with protocols of "file", "http", and "https". There currently is no additional control when using HTTP/HTTPS.
func WithMaxRuntimes ¶
func WithMaxRuntimes(n int) func(*Interpreter) error
Types ¶
type Config ¶
type Config struct {
Source string `json:"source,omitempty"`
}
Config can be passed into NewFilter() in order to configure the behavior of the sender.
func (Config) WithDefaults ¶
WithDefaults will set default values
type Filter ¶
func (*Filter) EventErrorCount ¶ added in v1.1.2
func (*Filter) EventErrorVelocity ¶ added in v1.1.2
func (*Filter) EventFilterCount ¶ added in v1.1.2
func (*Filter) EventFilterVelocity ¶ added in v1.1.2
func (*Filter) EventSuccessCount ¶ added in v1.1.2
func (*Filter) EventSuccessVelocity ¶ added in v1.1.2
type Interpreter ¶
type Interpreter struct { sync.Mutex // Provider is a pluggable library provider, which can be used // instead of (or in addition to) the standard Provide method, // which will just use DefaultProvider if this Provider is // nil. // // A problem: For a multitenant service, we need some access // control. If a single LibraryProvider will provide all the // libraries for all tenants, we need a mechanism to provide // access control. We could add another parameter that // carries the required data (something related to tenant // name), but it's hard to provide something generic. With // trepidation, perhaps just use a Value in the ctx? LibraryProvider func(interpreter *Interpreter, libraryName string) (string, error) EnvSetter func(o *goja.Runtime, env map[string]interface{}) // contains filtered or unexported fields }
Interpreter implements an interpreter based on Goja, which is a Go implementation of ECMAScript 5.1+.
See https://github.com/dop251/goja.
func NewInterpreter ¶
func NewInterpreter(options ...func(*Interpreter) error) (*Interpreter, error)
func (*Interpreter) Compile ¶
func (interpreter *Interpreter) Compile(code string) (interface{}, error)
Compile calls goja.Compile after compiling libraries if any. This method can block if the interpreter's library Provider blocks in order to obtain external libraries.
func (*Interpreter) CompileLibrary ¶
func (interpreter *Interpreter) CompileLibrary(name, src string) (interface{}, error)
CompileLibraries checks any libraries at LibrarySources.
This method originally precompiled these libraries, but goja doesn't currently support combining ast.Programs. So we won't actually use anything we precompile! Perhaps in the future. But we can at least check that the libraries do in fact compile.
func (*Interpreter) ProvideLibrary ¶
func (interpreter *Interpreter) ProvideLibrary(name string) (string, error)
ProvideLibrary resolves the library name into a library.
We experimented with other approaches including returning parsed code and a struct representing a library. Probably will want to move back in that direction.
type Program ¶
Interpreter implements an interpreter based on Goja, which is a Go implementation of ECMAScript 5.1+.