package core
import "github.com/purpleidea/mgmt/lang/core"
Package core contains core functions and other related facilities which are used in programs.
Index ¶
- Constants
- func Asset(name string) ([]byte, error)
- func AssetNames() ([]string, error)
- func Concat(ctx context.Context, input []types.Value) (types.Value, error)
- func Contains(ctx context.Context, input []types.Value) (types.Value, error)
- func Len(ctx context.Context, input []types.Value) (types.Value, error)
- func ListLookup(ctx context.Context, input []types.Value) (types.Value, error)
- func ListLookupDefault(ctx context.Context, input []types.Value) (types.Value, error)
- func MapLookup(ctx context.Context, input []types.Value) (types.Value, error)
- func MapLookupDefault(ctx context.Context, input []types.Value) (types.Value, error)
- func Panic(ctx context.Context, input []types.Value) (types.Value, error)
- type HistoryFunc
- func (obj *HistoryFunc) ArgGen(index int) (string, error)
- func (obj *HistoryFunc) Build(typ *types.Type) (*types.Type, error)
- func (obj *HistoryFunc) Info() *interfaces.Info
- func (obj *HistoryFunc) Init(init *interfaces.Init) error
- func (obj *HistoryFunc) Stream(ctx context.Context) error
- func (obj *HistoryFunc) String() string
- func (obj *HistoryFunc) Validate() error
- type LookupDefaultFunc
- func (obj *LookupDefaultFunc) ArgGen(index int) (string, error)
- func (obj *LookupDefaultFunc) Build(typ *types.Type) (*types.Type, error)
- func (obj *LookupDefaultFunc) Call(ctx context.Context, args []types.Value) (types.Value, error)
- func (obj *LookupDefaultFunc) Info() *interfaces.Info
- func (obj *LookupDefaultFunc) Init(init *interfaces.Init) error
- func (obj *LookupDefaultFunc) Stream(ctx context.Context) error
- func (obj *LookupDefaultFunc) String() string
- func (obj *LookupDefaultFunc) Validate() error
- type LookupFunc
- func (obj *LookupFunc) ArgGen(index int) (string, error)
- func (obj *LookupFunc) Build(typ *types.Type) (*types.Type, error)
- func (obj *LookupFunc) Call(ctx context.Context, args []types.Value) (types.Value, error)
- func (obj *LookupFunc) FuncInfer(partialType *types.Type, partialValues []types.Value) (*types.Type, []*interfaces.UnificationInvariant, error)
- func (obj *LookupFunc) Info() *interfaces.Info
- func (obj *LookupFunc) Init(init *interfaces.Init) error
- func (obj *LookupFunc) Stream(ctx context.Context) error
- func (obj *LookupFunc) String() string
- func (obj *LookupFunc) Validate() error
- type Random1Func
- func (obj *Random1Func) ArgGen(index int) (string, error)
- func (obj *Random1Func) Info() *interfaces.Info
- func (obj *Random1Func) Init(init *interfaces.Init) error
- func (obj *Random1Func) Stream(ctx context.Context) error
- func (obj *Random1Func) String() string
- func (obj *Random1Func) Validate() error
- type StructLookupFunc
- func (obj *StructLookupFunc) ArgGen(index int) (string, error)
- func (obj *StructLookupFunc) Build(typ *types.Type) (*types.Type, error)
- func (obj *StructLookupFunc) Call(ctx context.Context, args []types.Value) (types.Value, error)
- func (obj *StructLookupFunc) Copy() interfaces.Func
- func (obj *StructLookupFunc) FuncInfer(partialType *types.Type, partialValues []types.Value) (*types.Type, []*interfaces.UnificationInvariant, error)
- func (obj *StructLookupFunc) Info() *interfaces.Info
- func (obj *StructLookupFunc) Init(init *interfaces.Init) error
- func (obj *StructLookupFunc) Stream(ctx context.Context) error
- func (obj *StructLookupFunc) String() string
- func (obj *StructLookupFunc) Validate() error
- type StructLookupOptionalFunc
- func (obj *StructLookupOptionalFunc) ArgGen(index int) (string, error)
- func (obj *StructLookupOptionalFunc) Build(typ *types.Type) (*types.Type, error)
- func (obj *StructLookupOptionalFunc) Call(ctx context.Context, args []types.Value) (types.Value, error)
- func (obj *StructLookupOptionalFunc) Copy() interfaces.Func
- func (obj *StructLookupOptionalFunc) FuncInfer(partialType *types.Type, partialValues []types.Value) (*types.Type, []*interfaces.UnificationInvariant, error)
- func (obj *StructLookupOptionalFunc) Info() *interfaces.Info
- func (obj *StructLookupOptionalFunc) Init(init *interfaces.Init) error
- func (obj *StructLookupOptionalFunc) Stream(ctx context.Context) error
- func (obj *StructLookupOptionalFunc) String() string
- func (obj *StructLookupOptionalFunc) Validate() error
Constants ¶
const ( // ConcatFuncName is the name this function is registered as. ConcatFuncName = funcs.ConcatFuncName )
const ( // ContainsFuncName is the name this function is registered as. ContainsFuncName = funcs.ContainsFuncName )
const ( // HistoryFuncName is the name this function is registered as. // TODO: move this into a separate package HistoryFuncName = "history" )
const ( // ListLookupDefaultFuncName is the name this function is registered as. ListLookupDefaultFuncName = "list_lookup_default" )
const ( // ListLookupFuncName is the name this function is registered as. ListLookupFuncName = "list_lookup" )
const ( // LookupDefaultFuncName is the name this function is registered as. // This starts with an underscore so that it cannot be used from the // lexer. LookupDefaultFuncName = funcs.LookupDefaultFuncName )
const ( // LookupFuncName is the name this function is registered as. // This starts with an underscore so that it cannot be used from the // lexer. LookupFuncName = funcs.LookupFuncName )
const ( // MapLookupDefaultFuncName is the name this function is registered as. MapLookupDefaultFuncName = "map_lookup_default" )
const ( // MapLookupFuncName is the name this function is registered as. MapLookupFuncName = "map_lookup" )
const ( // Random1FuncName is the name this function is registered as. Random1FuncName = "random1" )
const ( // StructLookupFuncName is the name this function is registered as. This // starts with an underscore so that it cannot be used from the lexer. StructLookupFuncName = funcs.StructLookupFuncName )
const ( // StructLookupOptionalFuncName is the name this function is registered // as. This starts with an underscore so that it cannot be used from the // lexer. StructLookupOptionalFuncName = funcs.StructLookupOptionalFuncName )
Functions ¶
func Asset ¶
Asset returns the contents of an embedded .mcl file.
func AssetNames ¶
AssetNames returns a flattened list of embedded .mcl file paths.
func Concat ¶
Concat concatenates two strings together.
func Contains ¶
Contains checks if a needle exists in a haystack, which is a list.
func Len ¶
Len returns the number of elements in a list or the number of key pairs in a map. It can operate on either of these types.
func ListLookup ¶
ListLookup returns the value corresponding to the input index in the list.
func ListLookupDefault ¶
ListLookupDefault returns the value corresponding to the input index in the list. If the value is not present, it returns the default value supplied.
func MapLookup ¶
MapLookup returns the value corresponding to the input key in the map.
func MapLookupDefault ¶
MapLookupDefault returns the value corresponding to the input key in the map. If the value is not present, it returns the default value supplied.
func Panic ¶
Panic returns an error when it receives a non-empty string or a true boolean. The error should cause the function engine to shutdown. If there's no error, it returns false.
Types ¶
type HistoryFunc ¶
type HistoryFunc struct { Type *types.Type // type of input value (same as output type) // contains filtered or unexported fields }
HistoryFunc is special function which returns the Nth oldest value seen. It must store up incoming values until it gets enough to return the desired one. A restart of the program, will expunge the stored state. This obviously takes more memory, the further back you wish to index. A change in the index var is generally not useful, but it is permitted. Moving it to a smaller value will cause older index values to be expunged. If this is undesirable, a max count could be added. This was not implemented with efficiency in mind. Since some functions might not send out un-changed values, it might also make sense to implement a *time* based hysteresis, since this only looks at the last N changed values. A time based hysteresis would tick every precision-width, and store whatever the latest value at that time is.
func (*HistoryFunc) ArgGen ¶
func (obj *HistoryFunc) ArgGen(index int) (string, error)
ArgGen returns the Nth arg name for this function.
func (*HistoryFunc) Build ¶
Build takes the now known function signature and stores it so that this function can appear to be static. That type is used to build our function statically.
func (*HistoryFunc) Info ¶
func (obj *HistoryFunc) Info() *interfaces.Info
Info returns some static info about itself.
func (*HistoryFunc) Init ¶
func (obj *HistoryFunc) Init(init *interfaces.Init) error
Init runs some startup code for this function.
func (*HistoryFunc) Stream ¶
func (obj *HistoryFunc) Stream(ctx context.Context) error
Stream returns the changing values that this func has over time.
func (*HistoryFunc) String ¶
func (obj *HistoryFunc) String() string
String returns a simple name for this function. This is needed so this struct can satisfy the pgraph.Vertex interface.
func (*HistoryFunc) Validate ¶
func (obj *HistoryFunc) Validate() error
Validate makes sure we've built our struct properly. It is usually unused for normal functions that users can use directly.
type LookupDefaultFunc ¶
type LookupDefaultFunc struct { Type *types.Type // Kind == List OR Map, that is used as the list/map we lookup in // contains filtered or unexported fields }
LookupDefaultFunc is a list index or map key lookup function. It does both because the current syntax in the parser is identical, so it's convenient to mix the two together. This calls out to some of the code in the ListLookupDefaultFunc and MapLookupDefaultFunc implementations. If the index or key for this input doesn't exist, then it will return the default value you specified for this function. TODO: Eventually we will deprecate this function when the function engine can support passing a value for erroring functions. (Bad index could be an err!)
func (*LookupDefaultFunc) ArgGen ¶
func (obj *LookupDefaultFunc) ArgGen(index int) (string, error)
ArgGen returns the Nth arg name for this function.
func (*LookupDefaultFunc) Build ¶
Build is run to turn the polymorphic, undetermined function, into the specific statically typed version. It is usually run after Unify completes, and must be run before Info() and any of the other Func interface methods are used. This function is idempotent, as long as the arg isn't changed between runs.
func (*LookupDefaultFunc) Call ¶
Call returns the result of this function.
func (*LookupDefaultFunc) Info ¶
func (obj *LookupDefaultFunc) Info() *interfaces.Info
Info returns some static info about itself. Build must be called before this will return correct data.
func (*LookupDefaultFunc) Init ¶
func (obj *LookupDefaultFunc) Init(init *interfaces.Init) error
Init runs some startup code for this function.
func (*LookupDefaultFunc) Stream ¶
func (obj *LookupDefaultFunc) Stream(ctx context.Context) error
Stream returns the changing values that this func has over time.
func (*LookupDefaultFunc) String ¶
func (obj *LookupDefaultFunc) String() string
String returns a simple name for this function. This is needed so this struct can satisfy the pgraph.Vertex interface.
func (*LookupDefaultFunc) Validate ¶
func (obj *LookupDefaultFunc) Validate() error
Validate tells us if the input struct takes a valid form.
type LookupFunc ¶
type LookupFunc struct { Type *types.Type // Kind == List OR Map, that is used as the list/map we lookup in // contains filtered or unexported fields }
LookupFunc is a list index or map key lookup function. It does both because the current syntax in the parser is identical, so it's convenient to mix the two together. This calls out to some of the code in the ListLookupFunc and MapLookupFunc implementations. If the index or key for this input doesn't exist, then it will return the zero value for that type. TODO: Eventually we will deprecate this function when the function engine can support passing a value for erroring functions. (Bad index could be an err!)
func (*LookupFunc) ArgGen ¶
func (obj *LookupFunc) ArgGen(index int) (string, error)
ArgGen returns the Nth arg name for this function.
func (*LookupFunc) Build ¶
Build is run to turn the polymorphic, undetermined function, into the specific statically typed version. It is usually run after Unify completes, and must be run before Info() and any of the other Func interface methods are used. This function is idempotent, as long as the arg isn't changed between runs.
func (*LookupFunc) Call ¶
Call returns the result of this function.
func (*LookupFunc) FuncInfer ¶
func (obj *LookupFunc) FuncInfer(partialType *types.Type, partialValues []types.Value) (*types.Type, []*interfaces.UnificationInvariant, error)
FuncInfer takes partial type and value information from the call site of this function so that it can build an appropriate type signature for it. The type signature may include unification variables.
func (*LookupFunc) Info ¶
func (obj *LookupFunc) Info() *interfaces.Info
Info returns some static info about itself. Build must be called before this will return correct data.
func (*LookupFunc) Init ¶
func (obj *LookupFunc) Init(init *interfaces.Init) error
Init runs some startup code for this function.
func (*LookupFunc) Stream ¶
func (obj *LookupFunc) Stream(ctx context.Context) error
Stream returns the changing values that this func has over time.
func (*LookupFunc) String ¶
func (obj *LookupFunc) String() string
String returns a simple name for this function. This is needed so this struct can satisfy the pgraph.Vertex interface.
func (*LookupFunc) Validate ¶
func (obj *LookupFunc) Validate() error
Validate tells us if the input struct takes a valid form.
type Random1Func ¶
type Random1Func struct {
// contains filtered or unexported fields
}
Random1Func returns one random string of a certain length. XXX: return a stream instead, and combine this with a first(?) function which takes the first value and then puts backpressure on the stream. This should notify parent functions somehow that their values are no longer required so that they can shutdown if possible. Maybe it should be returning a stream of floats [0,1] as well, which someone can later map to the alphabet that they want. Should random() take an interval to know how often to spit out values? It could also just do it once per second, and we could filter for less. If we want something high precision, we could add that in the future... We could name that "random" and this one can be "random1" until we deprecate it.
func (*Random1Func) ArgGen ¶
func (obj *Random1Func) ArgGen(index int) (string, error)
ArgGen returns the Nth arg name for this function.
func (*Random1Func) Info ¶
func (obj *Random1Func) Info() *interfaces.Info
Info returns some static info about itself.
func (*Random1Func) Init ¶
func (obj *Random1Func) Init(init *interfaces.Init) error
Init runs some startup code for this function.
func (*Random1Func) Stream ¶
func (obj *Random1Func) Stream(ctx context.Context) error
Stream returns the single value that was generated and then closes.
func (*Random1Func) String ¶
func (obj *Random1Func) String() string
String returns a simple name for this function. This is needed so this struct can satisfy the pgraph.Vertex interface.
func (*Random1Func) Validate ¶
func (obj *Random1Func) Validate() error
Validate makes sure we've built our struct properly. It is usually unused for normal functions that users can use directly.
type StructLookupFunc ¶
type StructLookupFunc struct { Type *types.Type // Kind == Struct, that is used as the struct we lookup Out *types.Type // type of field we're extracting // contains filtered or unexported fields }
StructLookupFunc is a struct field lookup function.
func (*StructLookupFunc) ArgGen ¶
func (obj *StructLookupFunc) ArgGen(index int) (string, error)
ArgGen returns the Nth arg name for this function.
func (*StructLookupFunc) Build ¶
Build is run to turn the polymorphic, undetermined function, into the specific statically typed version. It is usually run after Unify completes, and must be run before Info() and any of the other Func interface methods are used. This function is idempotent, as long as the arg isn't changed between runs.
func (*StructLookupFunc) Call ¶
Call returns the result of this function.
func (*StructLookupFunc) Copy ¶
func (obj *StructLookupFunc) Copy() interfaces.Func
Copy is implemented so that the obj.field value is not lost if we copy this function. That value is learned during FuncInfer, and previously would have been lost by the time we used it in Build.
func (*StructLookupFunc) FuncInfer ¶
func (obj *StructLookupFunc) FuncInfer(partialType *types.Type, partialValues []types.Value) (*types.Type, []*interfaces.UnificationInvariant, error)
FuncInfer takes partial type and value information from the call site of this function so that it can build an appropriate type signature for it. The type signature may include unification variables.
func (*StructLookupFunc) Info ¶
func (obj *StructLookupFunc) Info() *interfaces.Info
Info returns some static info about itself. Build must be called before this will return correct data.
func (*StructLookupFunc) Init ¶
func (obj *StructLookupFunc) Init(init *interfaces.Init) error
Init runs some startup code for this function.
func (*StructLookupFunc) Stream ¶
func (obj *StructLookupFunc) Stream(ctx context.Context) error
Stream returns the changing values that this func has over time.
func (*StructLookupFunc) String ¶
func (obj *StructLookupFunc) String() string
String returns a simple name for this function. This is needed so this struct can satisfy the pgraph.Vertex interface.
func (*StructLookupFunc) Validate ¶
func (obj *StructLookupFunc) Validate() error
Validate tells us if the input struct takes a valid form.
type StructLookupOptionalFunc ¶
type StructLookupOptionalFunc struct { Type *types.Type // Kind == Struct, that is used as the struct we lookup Out *types.Type // type of field we're extracting (also the type of optional) // contains filtered or unexported fields }
StructLookupOptionalFunc is a struct field lookup function. It does a special trick in that it will unify on a struct that doesn't have the specified field in it, but in that case, it will always return the optional value. This is a bit different from the "default" mechanism that is used by list and map lookup functions.
func (*StructLookupOptionalFunc) ArgGen ¶
func (obj *StructLookupOptionalFunc) ArgGen(index int) (string, error)
ArgGen returns the Nth arg name for this function.
func (*StructLookupOptionalFunc) Build ¶
Build is run to turn the polymorphic, undetermined function, into the specific statically typed version. It is usually run after Unify completes, and must be run before Info() and any of the other Func interface methods are used. This function is idempotent, as long as the arg isn't changed between runs.
func (*StructLookupOptionalFunc) Call ¶
func (obj *StructLookupOptionalFunc) Call(ctx context.Context, args []types.Value) (types.Value, error)
Call returns the result of this function.
func (*StructLookupOptionalFunc) Copy ¶
func (obj *StructLookupOptionalFunc) Copy() interfaces.Func
Copy is implemented so that the obj.field value is not lost if we copy this function. That value is learned during FuncInfer, and previously would have been lost by the time we used it in Build.
func (*StructLookupOptionalFunc) FuncInfer ¶
func (obj *StructLookupOptionalFunc) FuncInfer(partialType *types.Type, partialValues []types.Value) (*types.Type, []*interfaces.UnificationInvariant, error)
FuncInfer takes partial type and value information from the call site of this function so that it can build an appropriate type signature for it. The type signature may include unification variables.
func (*StructLookupOptionalFunc) Info ¶
func (obj *StructLookupOptionalFunc) Info() *interfaces.Info
Info returns some static info about itself. Build must be called before this will return correct data.
func (*StructLookupOptionalFunc) Init ¶
func (obj *StructLookupOptionalFunc) Init(init *interfaces.Init) error
Init runs some startup code for this function.
func (*StructLookupOptionalFunc) Stream ¶
func (obj *StructLookupOptionalFunc) Stream(ctx context.Context) error
Stream returns the changing values that this func has over time.
func (*StructLookupOptionalFunc) String ¶
func (obj *StructLookupOptionalFunc) String() string
String returns a simple name for this function. This is needed so this struct can satisfy the pgraph.Vertex interface.
func (*StructLookupOptionalFunc) Validate ¶
func (obj *StructLookupOptionalFunc) Validate() error
Validate tells us if the input struct takes a valid form.
Source Files ¶
concat.go contains.go core.go history.go len.go list_lookup.go list_lookup_default.go lookup.go lookup_default.go map_lookup.go map_lookup_default.go panic.go random1.go struct_lookup.go struct_lookup_optional.go
Directories ¶
- Version
- v0.0.0-20250322185616-c50a578426f1 (latest)
- Published
- Mar 22, 2025
- Platform
- linux/amd64
- Imports
- 34 packages
- Last checked
- 4 days ago –
Tools for package owners.