refactor(kv): template readability.

This commit is contained in:
Fernandez Ludovic 2017-12-23 17:45:51 +01:00 committed by Traefiker
parent be0dd71bb4
commit c95393b238

View file

@ -1,38 +1,26 @@
{{$frontends := List .Prefix "/frontends/" }} [backends]
{{$backends := List .Prefix "/backends/"}} {{range $backend := List .Prefix "/backends/"}}
{{$tlsconfiguration := List .Prefix "/tlsconfiguration/"}}
[backends]{{range $backends}}
{{$backend := .}}
{{$backendName := Last $backend}} {{$backendName := Last $backend}}
{{$servers := ListServers $backend }}
{{$circuitBreaker := Get "" . "/circuitbreaker/" "expression"}} {{$circuitBreaker := Get "" $backend "/circuitbreaker/expression"}}
{{with $circuitBreaker}} {{with $circuitBreaker}}
[backends."{{$backendName}}".circuitBreaker] [backends."{{$backendName}}".circuitBreaker]
expression = "{{$circuitBreaker}}" expression = "{{$circuitBreaker}}"
{{end}} {{end}}
{{$loadBalancer := Get "" . "/loadbalancer/" "method"}} {{$loadBalancer := Get "" $backend "/loadbalancer/method"}}
{{with $loadBalancer}} {{with $loadBalancer}}
[backends."{{$backendName}}".loadBalancer] [backends."{{$backendName}}".loadBalancer]
method = "{{$loadBalancer}}" method = "{{$loadBalancer}}"
sticky = {{ getSticky . }} sticky = {{ getSticky $backend }}
{{if hasStickinessLabel $backend}} {{if hasStickinessLabel $backend}}
[backends."{{$backendName}}".loadBalancer.stickiness] [backends."{{$backendName}}".loadBalancer.stickiness]
cookieName = "{{getStickinessCookieName $backend}}" cookieName = "{{getStickinessCookieName $backend}}"
{{end}} {{end}}
{{end}} {{end}}
{{$healthCheck := Get "" . "/healthcheck/" "path"}} {{$maxConnAmt := Get "" $backend "/maxconn/amount"}}
{{with $healthCheck}} {{$maxConnExtractorFunc := Get "" $backend "/maxconn/extractorfunc"}}
[backends."{{$backendName}}".healthCheck]
path = "{{$healthCheck}}"
interval = "{{ Get "30s" $backend "/healthcheck/" "interval" }}"
{{end}}
{{$maxConnAmt := Get "" . "/maxconn/" "amount"}}
{{$maxConnExtractorFunc := Get "" . "/maxconn/" "extractorfunc"}}
{{with $maxConnAmt}} {{with $maxConnAmt}}
{{with $maxConnExtractorFunc}} {{with $maxConnExtractorFunc}}
[backends."{{$backendName}}".maxConn] [backends."{{$backendName}}".maxConn]
@ -41,38 +29,53 @@
{{end}} {{end}}
{{end}} {{end}}
{{range $servers}} {{$healthCheck := Get "" $backend "/healthcheck/path"}}
[backends."{{$backendName}}".servers."{{Last .}}"] {{with $healthCheck}}
url = "{{Get "" . "/url"}}" [backends."{{$backendName}}".healthCheck]
weight = {{Get "0" . "/weight"}} path = "{{$healthCheck}}"
{{end}} interval = "{{ Get "30s" $backend "/healthcheck/interval" }}"
{{end}} {{end}}
[frontends]{{range $frontends}} {{range $server := ListServers $backend}}
{{$frontend := Last .}} [backends."{{$backendName}}".servers."{{Last $server}}"]
{{$entryPoints := SplitGet . "/entrypoints"}} url = "{{Get "" $server "/url"}}"
[frontends."{{$frontend}}"] weight = {{Get "0" $server "/weight"}}
backend = "{{Get "" . "/backend"}}" {{end}}
passHostHeader = {{Get "true" . "/passHostHeader"}}
priority = {{Get "0" . "/priority"}} {{end}}
[frontends]
{{range $frontend := List .Prefix "/frontends/" }}
{{$frontendName := Last $frontend}}
[frontends."{{$frontendName}}"]
backend = "{{Get "" $frontend "/backend"}}"
priority = {{Get "0" $frontend "/priority"}}
passHostHeader = {{Get "true" $frontend "/passHostHeader"}}
{{$entryPoints := SplitGet $frontend "/entrypoints"}}
entryPoints = [{{range $entryPoints}} entryPoints = [{{range $entryPoints}}
"{{.}}", "{{.}}",
{{end}}] {{end}}]
{{$routes := List . "/routes/"}}
{{range $routes}} {{range $route := List $frontend "/routes/"}}
[frontends."{{$frontend}}".routes."{{Last .}}"] [frontends."{{$frontendName}}".routes."{{Last $route}}"]
rule = "{{Get "" . "/rule"}}" rule = "{{Get "" $route "/rule"}}"
{{end}}
{{end}} {{end}}
{{range $tlsconfiguration}} {{end}}
{{$entryPoints := SplitGet . "/entrypoints"}}
{{range $tlsConfiguration := List .Prefix "/tlsconfiguration/"}}
[[tlsConfiguration]] [[tlsConfiguration]]
{{$entryPoints := SplitGet $tlsConfiguration "/entrypoints"}}
entryPoints = [{{range $entryPoints}} entryPoints = [{{range $entryPoints}}
"{{.}}", "{{.}}",
{{end}}] {{end}}]
[tlsConfiguration.certificate]
certFile = """{{Get "" . "/certificate" "/certfile"}}"""
keyFile = """{{Get "" . "/certificate" "/keyfile"}}"""
{{end}}
[tlsConfiguration.certificate]
certFile = """{{Get "" $tlsConfiguration "/certificate/certfile"}}"""
keyFile = """{{Get "" $tlsConfiguration "/certificate/keyfile"}}"""
{{end}}