package vars
import "github.com/purpleidea/mgmt/lang/funcs/vars"
Package vars provides a framework for language vars.
Index ¶
- Constants
- func Lookup(name string) (interfaces.Var, error)
- func LookupPrefix(prefix string) map[string]func() interfaces.Var
- func Map() map[string]func() interfaces.Var
- func ModuleRegister(module, name string, v func() interfaces.Var)
- func Register(name string, fn func() interfaces.Var)
- func RegisterResourceParam(kind, param, field string, value func() interfaces.Var)
- func RegisterResourceParams(kind string, params map[string]map[string]func() interfaces.Var)
- type Value
Constants ¶
const ( // ConstNamespace is the string prefix for all top-level built-in vars. ConstNamespace = "const" // ResourceNamespace is the string prefix for all top-level resource // specific built-in vars, that exist under the ConstNamespace header. ResourceNamespace = "res" )
Functions ¶
func Lookup ¶
func Lookup(name string) (interfaces.Var, error)
Lookup returns a pointer to the var implementation.
func LookupPrefix ¶
func LookupPrefix(prefix string) map[string]func() interfaces.Var
LookupPrefix returns a map of names to vars that start with a module prefix. This search automatically adds the period separator. So if you want vars in the `const` prefix, search for `const`, not `const.` and it will find all the correctly registered vars. 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.Var
Map returns a map from all registered var names to a function to return that one. We return a copy of our internal registered var store so that this result can be manipulated safely. We return the vars that produce the Var interface because we might use this result to create multiple vars, and each one might need to have its own unique memory address to work properly.
func ModuleRegister ¶
func ModuleRegister(module, name string, v func() interfaces.Var)
ModuleRegister is exactly like Register, except that it registers within a named module. This is a helper function.
func Register ¶
func Register(name string, fn func() interfaces.Var)
Register takes a var and its name and makes it available for use. It is commonly called in the init() method of the var at program startup. There is no matching Unregister function.
func RegisterResourceParam ¶
func RegisterResourceParam(kind, param, field string, value func() interfaces.Var)
RegisterResourceParam registers a single const param for a resource. You might prefer to use RegisterResourceParams instead.
func RegisterResourceParams ¶
func RegisterResourceParams(kind string, params map[string]map[string]func() interfaces.Var)
RegisterResourceParams registers a map of const params for a resource. The params mapping keys are the param name and the param field name. Finally, the value is the specific type value for that constant.
Types ¶
type Value ¶
type Value = interfaces.Var
Value is a shortcut to using this type. XXX: Eventually we might get rid of this entirely and use types.Value instead of interfaces.Var which seems to be unnecessary at the moment.
Source Files ¶
- Version
- v0.0.0-20250322185616-c50a578426f1 (latest)
- Published
- Mar 22, 2025
- Platform
- linux/amd64
- Imports
- 3 packages
- Last checked
- 4 days ago –
Tools for package owners.