Documentation ¶
Overview ¶
Example (Option) ¶
Example_option demonstrates retrieving an option value from a scope object
package main import ( "context" "fmt" "os" "github.com/influxdata/flux/dependencies/dependenciestest" _ "github.com/influxdata/flux/fluxinit/static" "github.com/influxdata/flux/runtime" ) func main() { // Import the universe package. importer := runtime.StdLib() universe, _ := importer.ImportPackageObject("universe") // Retrieve the default value for the now option nowFunc, _ := universe.Get("now") // The now option is a function value whose default behavior is to return // the current system time when called. The function now() doesn't take // any arguments so can be called with nil. nowTime, _ := nowFunc.Function().Call(dependenciestest.Default().Inject(context.TODO()), nil) fmt.Fprintf(os.Stderr, "The current system time (UTC) is: %v\n", nowTime) }
Output:
Example (OverrideDefaultOptionExternally) ¶
Example_overrideDefaultOptionExternally demonstrates how declaring an option in a Flux script will change that option's binding globally.
package main import ( "context" "fmt" "github.com/influxdata/flux/dependencies/dependenciestest" _ "github.com/influxdata/flux/fluxinit/static" "github.com/influxdata/flux/runtime" ) func main() { queryString := ` option now = () => 2018-07-13T00:00:00Z what_time_is_it = now()` ctx := dependenciestest.Default().Inject(context.Background()) _, scope, err := runtime.Eval(ctx, queryString) if err != nil { fmt.Println(err) } // After evaluating the package, lookup the value of what_time_is_it now, _ := scope.Lookup("what_time_is_it") // what_time_is_it? Why it's .... fmt.Printf("The new current time (UTC) is: %v", now) }
Output: The new current time (UTC) is: 2018-07-13T00:00:00.000000000Z
Index ¶
- Variables
- func AnalyzePackage(astPkg flux.ASTHandle) (*semantic.Package, error)
- func AnalyzeSource(fluxSrc string) (*semantic.Package, error)
- func Eval(ctx context.Context, flux string, opts ...flux.ScopeMutator) ([]interpreter.SideEffect, values.Scope, error)
- func EvalAST(ctx context.Context, astPkg *ast.Package, opts ...flux.ScopeMutator) ([]interpreter.SideEffect, values.Scope, error)
- func EvalOptions(ctx context.Context, astPkg *ast.Package, opts []flux.ScopeMutator) ([]interpreter.SideEffect, values.Scope, error)
- func FinalizeBuiltIns()
- func LookupBuiltinType(pkg, name string) (semantic.MonoType, error)
- func MergePackages(dst, src flux.ASTHandle) error
- func MustLookupBuiltinType(pkg, name string) semantic.MonoType
- func Parse(flux string) (flux.ASTHandle, error)
- func ParseToJSON(flux string) ([]byte, error)
- func Prelude() values.Scope
- func RegisterPackage(pkg *ast.Package)
- func RegisterPackageValue(pkgpath, name string, value values.Value)
- func ReplacePackageValue(pkgpath, name string, value values.Value)
- func StdLib() interpreter.Importer
- func TypeEnvMap(env *fbsemantic.TypeEnvironment) map[envKey]*fbsemantic.Prop
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Default = &runtime{}
Default contains the preregistered packages and builtin values required to execute a flux script.
var ( // list of packages included in the prelude. // Packages must be listed in import order PreludeList = []string{ "internal/boolean", "universe", "influxdata/influxdb", } )
Functions ¶
func AnalyzeSource ¶
AnalyzeSource parses and analyzes the given Flux source, using libflux.
func Eval ¶
func Eval(ctx context.Context, flux string, opts ...flux.ScopeMutator) ([]interpreter.SideEffect, values.Scope, error)
Eval accepts a Flux script and evaluates it to produce a set of side effects (as a slice of values) and a scope.
func EvalAST ¶
func EvalAST(ctx context.Context, astPkg *ast.Package, opts ...flux.ScopeMutator) ([]interpreter.SideEffect, values.Scope, error)
EvalAST accepts a Flux AST and evaluates it to produce a set of side effects (as a slice of values) and a scope.
func EvalOptions ¶
func EvalOptions(ctx context.Context, astPkg *ast.Package, opts []flux.ScopeMutator) ([]interpreter.SideEffect, values.Scope, error)
EvalOptions is like EvalAST, but only evaluates options.
func FinalizeBuiltIns ¶
func FinalizeBuiltIns()
FinalizeBuiltIns must be called to complete registration. Future calls to RegisterFunction or RegisterPackageValue will panic.
func LookupBuiltinType ¶
LookupBuiltinType returns the type of the builtin value for a given Flux stdlib package. Returns an error if lookup fails.
func MergePackages ¶
func MustLookupBuiltinType ¶
MustLookupBuiltinType validates that call to LookupBuiltInType was successful. If there is an error with lookup, then panic.
func ParseToJSON ¶
func RegisterPackage ¶
RegisterPackage adds a builtin package
func RegisterPackageValue ¶
RegisterPackageValue adds a value for an identifier in a builtin package
func ReplacePackageValue ¶
ReplacePackageValue replaces a value for an identifier in a builtin package
func StdLib ¶
func StdLib() interpreter.Importer
StdLib returns an importer for the Flux standard library.
func TypeEnvMap ¶
func TypeEnvMap(env *fbsemantic.TypeEnvironment) map[envKey]*fbsemantic.Prop
TypeEnvMap creates a global map of the TypeEnvironment
Types ¶
This section is empty.