fix: list entries parsing.
This commit is contained in:
parent
e74a20de24
commit
d88554fa92
3 changed files with 31 additions and 2 deletions
|
@ -572,7 +572,7 @@ var _templatesKvTmpl = []byte(`{{$frontends := List .Prefix "/frontends/" }}
|
|||
|
||||
[frontends]{{range $frontends}}
|
||||
{{$frontend := Last .}}
|
||||
{{$entryPoints := SplitGet . "/entrypoints"}}
|
||||
{{$entryPoints := GetList . "/entrypoints"}}
|
||||
[frontends."{{$frontend}}"]
|
||||
backend = "{{Get "" . "/backend"}}"
|
||||
passHostHeader = {{Get "true" . "/passHostHeader"}}
|
||||
|
|
|
@ -147,6 +147,7 @@ func (p *Provider) loadConfig() *types.Configuration {
|
|||
"getSticky": p.getSticky,
|
||||
"hasStickinessLabel": p.hasStickinessLabel,
|
||||
"getStickinessCookieName": p.getStickinessCookieName,
|
||||
"GetList": p.getList,
|
||||
}
|
||||
|
||||
configuration, err := p.GetConfiguration("templates/kv.tmpl", KvFuncMap, templateObjects)
|
||||
|
@ -264,3 +265,31 @@ func (p *Provider) hasStickinessLabel(rootPath string) bool {
|
|||
func (p *Provider) getStickinessCookieName(rootPath string) string {
|
||||
return p.get("", rootPath, "/loadbalancer", "/stickiness", "/cookiename")
|
||||
}
|
||||
|
||||
func (p *Provider) getList(keyParts ...string) []string {
|
||||
values := p.splitGet(keyParts...)
|
||||
if len(values) > 0 {
|
||||
return values
|
||||
}
|
||||
|
||||
return p.getSlice(keyParts...)
|
||||
}
|
||||
|
||||
// get sub keys. ex: foo/0, foo/1, foo/2
|
||||
func (p *Provider) getSlice(keyParts ...string) []string {
|
||||
baseKey := strings.Join(keyParts, "")
|
||||
if !strings.HasSuffix(baseKey, "/") {
|
||||
baseKey += "/"
|
||||
}
|
||||
|
||||
listKeys := p.list(baseKey)
|
||||
|
||||
var values []string
|
||||
for _, entryKey := range listKeys {
|
||||
val := p.get("", entryKey)
|
||||
if len(val) > 0 {
|
||||
values = append(values, val)
|
||||
}
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
|
||||
[frontends]{{range $frontends}}
|
||||
{{$frontend := Last .}}
|
||||
{{$entryPoints := SplitGet . "/entrypoints"}}
|
||||
{{$entryPoints := GetList . "/entrypoints"}}
|
||||
[frontends."{{$frontend}}"]
|
||||
backend = "{{Get "" . "/backend"}}"
|
||||
passHostHeader = {{Get "true" . "/passHostHeader"}}
|
||||
|
|
Loading…
Reference in a new issue