Skip to content

Conversation

Vigilans
Copy link
Contributor

@Vigilans Vigilans commented Dec 23, 2024

This PR adds support for named mappings's syntax ${name[key]} in template package.

Named Mappings

By Mapping, we mean a user-supplied function to lookup value from key: type Mapping func(string) (string, bool). In compose it is provided with environment lookup.

A named mappings is a collection of Mapping, indexed by name key. It allows temporarily switching to another mapping other than default during interpolation.

Template Syntax

Named mapping are used with syntax ${name[key]}, where an alternative Mapping is retrieved by key name, and looked up using key key.

It supports all functions in default mappings: ${name[key]:-default}, ${name[key]:+presence}, ${name[key]?error}.

It also supports mapping key to be a templated value, e.g. ${env[DIR_${container[replica-index]}]}.

Vigilans added 9 commits June 2, 2024 14:08
…ithDefaultWhenAbsence` and `withRequired` functions

* By directly using `Substitute` function, `Config` cannot pass further, thus not preserved

Signed-off-by: Vigilans <[email protected]>
* Named mapping is enabled only when `Config.namedMappings` is provided, otherwise compatibility is kept

Signed-off-by: Vigilans <[email protected]>
* Support formats like `${mapping[key]:-defaultValue}` `${mapping[key]:+presenceValue}`
* Support detecting presence of key in a named mapping through `${mapping[key]?errorMessage}`

Signed-off-by: Vigilans <[email protected]>
* So named mappings can use panic to report error

Signed-off-by: Vigilans <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant