package funcs
import "github.com/purpleidea/mgmt/lang/funcs"
Package funcs provides a framework for functions that change over time.
Index ¶
- Constants
- func GetFunctionMetadata(fn interface{}) (*docsUtil.Metadata, error)
- func GetFunctionName(fn interface{}) string
- func Lookup(name string) (interfaces.Func, error)
- func LookupPrefix(prefix string) map[string]func() interfaces.Func
- func Map() map[string]func() interfaces.Func
- func ModuleRegister(module, name string, fn func() interfaces.Func)
- func PureFuncExec(handle interfaces.Func, args []types.Value) (types.Value, error)
- func Register(name string, fn func() interfaces.Func)
Constants ¶
const ( // ModuleSep is the character used for the module scope separation. For // example when using `fmt.printf` or `math.sin` this is the char used. // It is included here for convenience when importing this package. ModuleSep = interfaces.ModuleSep // ReplaceChar is a special char that is used to replace ModuleSep when // it can't be used for some reason. This currently only happens in the // golang template library. Even with this limitation in that library, // we don't want to allow this as the first or last character in a name. // NOTE: the template library will panic if it is one of: .-# ReplaceChar = "_" // CoreDir is the directory prefix where core mcl code is embedded. CoreDir = "core/" // FunctionsRelDir is the path where the functions are kept, relative to // the main source code root. FunctionsRelDir = "lang/core/" // ConcatFuncName is the name the concat function is registered as. It // is listed here because it needs a well-known name that can be used by // the string interpolation code. ConcatFuncName = "concat" // ContainsFuncName is the name the contains function is registered as. ContainsFuncName = "contains" // LookupDefaultFuncName is the name this function is registered as. // This starts with an underscore so that it cannot be used from the // lexer. LookupDefaultFuncName = "_lookup_default" // LookupFuncName is the name this function is registered as. // This starts with an underscore so that it cannot be used from the // lexer. LookupFuncName = "_lookup" // StructLookupFuncName is the name this function is registered as. This // starts with an underscore so that it cannot be used from the lexer. StructLookupFuncName = "_struct_lookup" // StructLookupOptionalFuncName is the name this function is registered // as. This starts with an underscore so that it cannot be used from the // lexer. StructLookupOptionalFuncName = "_struct_lookup_optional" )
Functions ¶
func GetFunctionMetadata ¶
GetFunctionMetadata builds a metadata struct with everything about this func.
func GetFunctionName ¶
func GetFunctionName(fn interface{}) string
GetFunctionName reads the handle to find the underlying real function name. The function can be an actual function or a struct which implements one.
func Lookup ¶
func Lookup(name string) (interfaces.Func, error)
Lookup returns a pointer to the function's struct. It may be convertible to a BuildableFunc or InferableFunc if the particular function implements those additional methods.
func LookupPrefix ¶
func LookupPrefix(prefix string) map[string]func() interfaces.Func
LookupPrefix returns a map of names to functions that start with a module prefix. This search automatically adds the period separator. So if you want functions in the `fmt` package, search for `fmt`, not `fmt.` and it will find all the correctly registered functions. This removes that prefix from the result in the map keys that it returns. If you search for an empty prefix, then this will return all the top-level functions that aren't in a module.
func Map ¶
func Map() map[string]func() interfaces.Func
Map returns a map from all registered function names to a function to return that one. We return a copy of our internal registered function store so that this result can be manipulated safely. We return the functions that produce the Func interface because we might use this result to create multiple functions, and each one must have its own unique memory address to work properly.
func ModuleRegister ¶
func ModuleRegister(module, name string, fn func() interfaces.Func)
ModuleRegister is exactly like Register, except that it registers within a named module.
func PureFuncExec ¶
PureFuncExec is usually used to provisionally speculate about the result of a pure function, by running it once, and returning the result. Pure functions are expected to only produce one value that depends only on the input values. This won't run any slow functions either.
func Register ¶
func Register(name string, fn func() interfaces.Func)
Register takes a func and its name and makes it available for use. It is commonly called in the init() method of the func at program startup. There is no matching Unregister function. You may also register functions which satisfy the BuildableFunc and InferableFunc interfaces. To register a function which lives in a module, you must join the module name to the function name with the ModuleSep character. It is defined as a const and is probably the period character.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
lang/funcs/dage | Package dage implements a DAG function engine. |
lang/funcs/facts | Package facts provides a framework for language values that change over time. |
lang/funcs/funcgen | |
lang/funcs/funcgen/util | Package util provides some functions to be imported by the generated file. |
lang/funcs/multi | |
lang/funcs/operators | Package operators provides a helper library to load all of the built-in operators, which are actually just functions. |
lang/funcs/ref | Package ref implements reference counting for the graph API and function engine. |
lang/funcs/simple | |
lang/funcs/structs | |
lang/funcs/txn | Package txn contains the implementation of the graph transaction system. |
lang/funcs/vars | Package vars provides a framework for language vars. |
lang/funcs/wrapped |
- Version
- v0.0.0-20250322185616-c50a578426f1 (latest)
- Published
- Mar 22, 2025
- Platform
- linux/amd64
- Imports
- 10 packages
- Last checked
- 4 days ago –
Tools for package owners.