Comments (1)
I do the following, not perfect, but works when you can control the context:
func FuncMap() ttemplate.FuncMap {
f := sprig.TxtFuncMap()
f["getNested"] = getNested
return f
}
func getNested(d map[string]interface{}, key string) interface{} {
t := strings.Split(key, ".")
for i := 0; i < len(t); i++ {
if val, ok := d[t[i]]; ok {
if i+1 == len(t) {
return val
} else {
d = castAndGetMapStringInterface(val)
}
}
}
panic(fmt.Errorf("the map does not have a match for key %s", key))
}
func castAndGetMapStringInterface(i interface{}) map[string]interface{} {
m, ok := i.(map[string]interface{})
if ok {
return m
}
return nil
}
then in your template you can do:
{{getNested .ImageMap "ingress-controller.registry"}}
for struct:
type InterpolateContext struct {
ImageMap map[string]interface{}
}
from sprig.
Related Issues (20)
- Add location support to toDate and mustToDate
- substr doesn't respects runes (utf8 characters)
- (feat): Add tar.gz support
- `deepCopy`, will not override an integer value with the value `0`
- Function similar to nindent but ignoring content's initial new line.
- Feature request: add toYaml/fromYaml functions HOT 2
- help with merge inside range.
- sortAlpha does not work for list of numbers HOT 2
- sprig still alive? HOT 1
- support pipe for `omit` and `pick`
- Expose digFromDict function HOT 1
- (feat): Implement PBKDF2 as cryptographic function
- Time Comparison Functions HOT 4
- Parse Seconds from Duration HOT 2
- Map function
- How can I avoid getting a scientific notation in a large multiply? HOT 1
- How to convert "a b c" string to json ["a","b","c"]? HOT 1
- required function
- dateInZone silently fails when it doesn't understand the parameters passed to it
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sprig.