tmplvar

package
v0.0.0-...-de9e006 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2026 License: Apache-2.0 Imports: 16 Imported by: 1

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

Constants

This section is empty.

Variables

View Source
var JSONParser = Parser{
	Marshal:   json.Marshal,
	Unmarshal: json.Unmarshal,
}

JSONParser is a parser for JSON data

View Source
var YAMLParser = Parser{
	Marshal:   yaml.Marshal,
	Unmarshal: yaml.Unmarshal,
}

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

func GetPid

func GetPid(_ string, res Resolvable) (string, error)

GetPid resolves the %%pid%% template variable

func GetPort

func GetPort(tplVar string, res Resolvable) (string, error)

GetPort resolves the %%port%% 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL