Documentation
¶
Overview ¶
Package tmplvar provides functions to interact with template variables
Package tmplvar provides template variable resolution utilities that can be shared across components (autodiscovery, tagger, etc.)
Index ¶
- Variables
- func GetAdditionalTplVariables(tplVar string, res Resolvable) (string, error)
- func GetEnvvar(envVar string, res Resolvable) (string, error)
- func GetHost(tplVar string, res Resolvable) (string, error)
- func GetHostname(_ string, res Resolvable) (string, error)
- func GetPid(_ string, res Resolvable) (string, error)
- func GetPort(tplVar string, res Resolvable) (string, error)
- type NoResolverError
- type Parser
- type Resolvable
- type TemplateResolver
- type TemplateVar
- type VariableGetter
Constants ¶
This section is empty.
Variables ¶
JSONParser is a parser for JSON data
YAMLParser is a parser for YAML data
Functions ¶
func GetAdditionalTplVariables ¶
func GetAdditionalTplVariables(tplVar string, res Resolvable) (string, error)
GetAdditionalTplVariables resolves listener-specific template variables (%%kube_*%% and %%extra_*%%)
func GetEnvvar ¶
func GetEnvvar(envVar string, res Resolvable) (string, error)
GetEnvvar resolves the %%env_*%% template variable
func GetHost ¶
func GetHost(tplVar string, res Resolvable) (string, error)
GetHost resolves the %%host%% template variable
func GetHostname ¶
func GetHostname(_ string, res Resolvable) (string, error)
GetHostname resolves the %%hostname%% template variable
Types ¶
type NoResolverError ¶
type NoResolverError struct {
// contains filtered or unexported fields
}
NoResolverError represents an error that indicates that there's a problem with a service
func (*NoResolverError) Error ¶
func (n *NoResolverError) Error() string
Error returns the error message
type Parser ¶
type Parser struct {
Marshal func(interface{}) ([]byte, error)
Unmarshal func([]byte, interface{}) error
}
Parser handles marshaling/unmarshaling of data
type Resolvable ¶
type Resolvable interface {
// GetServiceID returns a unique identifier for this service (for error messages)
GetServiceID() string
// GetHosts returns a map of network name to IP address
GetHosts() (map[string]string, error)
// GetPorts returns the list of exposed ports
GetPorts() ([]workloadmeta.ContainerPort, error)
// GetPid returns the process ID
GetPid() (int, error)
// GetHostname returns the hostname
GetHostname() (string, error)
// GetExtraConfig returns listener-specific configuration (for %%kube_*%% and %%extra_*%%)
GetExtraConfig(key string) (string, error)
}
type TemplateResolver ¶
type TemplateResolver struct {
// contains filtered or unexported fields
}
func NewTemplateResolver ¶
func NewTemplateResolver(parser Parser, postProcessor func(interface{}) error, supportEnvVars bool) *TemplateResolver
func (TemplateResolver) ResolveDataWithTemplateVars ¶
func (t TemplateResolver) ResolveDataWithTemplateVars(data []byte, res Resolvable) ([]byte, error)
ResolveDataWithTemplateVars resolves template variables in a data structure (YAML/JSON). It walks through the tree structure and replaces %%var%% patterns in all strings. If postProcessor is not nil, it's called on the tree before marshaling back.
type TemplateVar ¶
type TemplateVar struct {
Raw, Name, Key []byte
}
TemplateVar is the info for a parsed template variable.
func Parse ¶
func Parse(b []byte) []TemplateVar
Parse returns parsed template variables found in the input data.
func ParseString ¶
func ParseString(s string) []TemplateVar
ParseString returns parsed template variables found in the input string.
type VariableGetter ¶
type VariableGetter func(key string, res Resolvable) (string, error)
VariableGetter is a function that resolves a template variable