package template
import "github.com/compose-spec/compose-go/v2/template"
Index ¶
- Variables
- func DefaultReplacementAppliedFunc(substring string, mapping Mapping, cfg *Config) (string, bool, error)
- func DefaultReplacementFunc(substring string, mapping Mapping, cfg *Config) (string, error)
- func ExtractVariables(configDict map[string]interface{}, pattern *regexp.Regexp) map[string]Variable
- func Substitute(template string, mapping Mapping) (string, error)
- func SubstituteWith(template string, mapping Mapping, pattern *regexp.Regexp, subsFuncs ...SubstituteFunc) (string, error)
- func SubstituteWithOptions(template string, mapping Mapping, options ...Option) (string, error)
- func WithoutLogging(cfg *Config)
- type Config
- type InvalidTemplateError
- type Mapping
- type MissingRequiredError
- type Option
- func WithPattern(pattern *regexp.Regexp) Option
- func WithReplacementFunction(replacementFunc ReplacementFunc) Option
- func WithSubstitutionFunction(subsFunc SubstituteFunc) Option
- type ReplacementFunc
- type SubstituteFunc
- type Variable
Variables ¶
var DefaultPattern = regexp.MustCompile(patternString)
Functions ¶
func DefaultReplacementAppliedFunc ¶
func DefaultReplacementAppliedFunc(substring string, mapping Mapping, cfg *Config) (string, bool, error)
func DefaultReplacementFunc ¶
func ExtractVariables ¶
func ExtractVariables(configDict map[string]interface{}, pattern *regexp.Regexp) map[string]Variable
ExtractVariables returns a map of all the variables defined in the specified compose file (dict representation) and their default value if any.
func Substitute ¶
Substitute variables in the string with their values
func SubstituteWith ¶
func SubstituteWith(template string, mapping Mapping, pattern *regexp.Regexp, subsFuncs ...SubstituteFunc) (string, error)
SubstituteWith substitute variables in the string with their values. It accepts additional substitute function.
func SubstituteWithOptions ¶
SubstituteWithOptions substitute variables in the string with their values. It accepts additional options such as a custom function or pattern.
func WithoutLogging ¶
func WithoutLogging(cfg *Config)
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
type InvalidTemplateError ¶
type InvalidTemplateError struct { Template string }
InvalidTemplateError is returned when a variable template is not in a valid format
func (InvalidTemplateError) Error ¶
func (e InvalidTemplateError) Error() string
type Mapping ¶
Mapping is a user-supplied function which maps from variable names to values. Returns the value as a string and a bool indicating whether the value is present, to distinguish between an empty string and the absence of a value.
type MissingRequiredError ¶
MissingRequiredError is returned when a variable template is missing
func (MissingRequiredError) Error ¶
func (e MissingRequiredError) Error() string
type Option ¶
type Option func(*Config)
func WithPattern ¶
func WithReplacementFunction ¶
func WithReplacementFunction(replacementFunc ReplacementFunc) Option
func WithSubstitutionFunction ¶
func WithSubstitutionFunction(subsFunc SubstituteFunc) Option
type ReplacementFunc ¶
ReplacementFunc is a user-supplied function that is apply to the matching substring. Returns the value as a string and an error.
type SubstituteFunc ¶
SubstituteFunc is a user-supplied function that apply substitution. Returns the value as a string, a bool indicating if the function could apply the substitution and an error.
type Variable ¶
Source Files ¶
- Version
- v2.4.8 (latest)
- Published
- Feb 10, 2025
- Platform
- linux/amd64
- Imports
- 6 packages
- Last checked
- 2 months ago –
Tools for package owners.