From 5623a53464dabd47f18353e14e8eaf3486779abd Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 23 Dec 2017 18:15:39 +0100 Subject: [PATCH] chore(kv): gen templates. --- autogen/gentemplates/gen.go | 119 ++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 58 deletions(-) diff --git a/autogen/gentemplates/gen.go b/autogen/gentemplates/gen.go index 2c101a63d..3f3758494 100644 --- a/autogen/gentemplates/gen.go +++ b/autogen/gentemplates/gen.go @@ -602,84 +602,87 @@ func templatesKubernetesTmpl() (*asset, error) { return a, nil } -var _templatesKvTmpl = []byte(`{{$frontends := List .Prefix "/frontends/" }} -{{$backends := List .Prefix "/backends/"}} -{{$tlsconfiguration := List .Prefix "/tlsconfiguration/"}} +var _templatesKvTmpl = []byte(`[backends] +{{range $backend := List .Prefix "/backends/"}} + {{$backendName := Last $backend}} -[backends]{{range $backends}} -{{$backend := .}} -{{$backendName := Last $backend}} -{{$servers := ListServers $backend }} - -{{$circuitBreaker := Get "" . "/circuitbreaker/" "expression"}} -{{with $circuitBreaker}} -[backends."{{$backendName}}".circuitBreaker] + {{$circuitBreaker := Get "" $backend "/circuitbreaker/expression"}} + {{with $circuitBreaker}} + [backends."{{$backendName}}".circuitBreaker] expression = "{{$circuitBreaker}}" -{{end}} + {{end}} -{{$loadBalancer := Get "" . "/loadbalancer/" "method"}} -{{with $loadBalancer}} -[backends."{{$backendName}}".loadBalancer] + {{$loadBalancer := Get "" $backend "/loadbalancer/method"}} + {{with $loadBalancer}} + [backends."{{$backendName}}".loadBalancer] method = "{{$loadBalancer}}" - sticky = {{ getSticky . }} + sticky = {{ getSticky $backend }} {{if hasStickinessLabel $backend}} [backends."{{$backendName}}".loadBalancer.stickiness] cookieName = "{{getStickinessCookieName $backend}}" {{end}} -{{end}} + {{end}} -{{$healthCheck := Get "" . "/healthcheck/" "path"}} -{{with $healthCheck}} -[backends."{{$backendName}}".healthCheck] - path = "{{$healthCheck}}" - interval = "{{ Get "30s" $backend "/healthcheck/" "interval" }}" -{{end}} - -{{$maxConnAmt := Get "" . "/maxconn/" "amount"}} -{{$maxConnExtractorFunc := Get "" . "/maxconn/" "extractorfunc"}} -{{with $maxConnAmt}} -{{with $maxConnExtractorFunc}} -[backends."{{$backendName}}".maxConn] + {{$maxConnAmt := Get "" $backend "/maxconn/amount"}} + {{$maxConnExtractorFunc := Get "" $backend "/maxconn/extractorfunc"}} + {{with $maxConnAmt}} + {{with $maxConnExtractorFunc}} + [backends."{{$backendName}}".maxConn] amount = {{$maxConnAmt}} extractorFunc = "{{$maxConnExtractorFunc}}" -{{end}} + {{end}} + {{end}} + + {{$healthCheck := Get "" $backend "/healthcheck/path"}} + {{with $healthCheck}} + [backends."{{$backendName}}".healthCheck] + path = "{{$healthCheck}}" + interval = "{{ Get "30s" $backend "/healthcheck/interval" }}" + {{end}} + + {{range $server := ListServers $backend}} + [backends."{{$backendName}}".servers."{{Last $server}}"] + url = "{{Get "" $server "/url"}}" + weight = {{Get "0" $server "/weight"}} + {{end}} + {{end}} -{{range $servers}} -[backends."{{$backendName}}".servers."{{Last .}}"] - url = "{{Get "" . "/url"}}" - weight = {{Get "0" . "/weight"}} -{{end}} -{{end}} +[frontends] +{{range $frontend := List .Prefix "/frontends/" }} + {{$frontendName := Last $frontend}} -[frontends]{{range $frontends}} - {{$frontend := Last .}} - {{$entryPoints := SplitGet . "/entrypoints"}} - [frontends."{{$frontend}}"] - backend = "{{Get "" . "/backend"}}" - passHostHeader = {{Get "true" . "/passHostHeader"}} - priority = {{Get "0" . "/priority"}} + [frontends."{{$frontendName}}"] + backend = "{{Get "" $frontend "/backend"}}" + priority = {{Get "0" $frontend "/priority"}} + passHostHeader = {{Get "true" $frontend "/passHostHeader"}} + + {{$entryPoints := SplitGet $frontend "/entrypoints"}} entryPoints = [{{range $entryPoints}} "{{.}}", - {{end}}] - {{$routes := List . "/routes/"}} - {{range $routes}} - [frontends."{{$frontend}}".routes."{{Last .}}"] - rule = "{{Get "" . "/rule"}}" - {{end}} + {{end}}] + + {{range $route := List $frontend "/routes/"}} + [frontends."{{$frontendName}}".routes."{{Last $route}}"] + rule = "{{Get "" $route "/rule"}}" + {{end}} + {{end}} -{{range $tlsconfiguration}} -{{$entryPoints := SplitGet . "/entrypoints"}} +{{range $tlsConfiguration := List .Prefix "/tlsconfiguration/"}} + [[tlsConfiguration]] - entryPoints = [{{range $entryPoints}} - "{{.}}", - {{end}}] - [tlsConfiguration.certificate] - certFile = """{{Get "" . "/certificate" "/certfile"}}""" - keyFile = """{{Get "" . "/certificate" "/keyfile"}}""" -{{end}} + {{$entryPoints := SplitGet $tlsConfiguration "/entrypoints"}} + entryPoints = [{{range $entryPoints}} + "{{.}}", + {{end}}] + + [tlsConfiguration.certificate] + certFile = """{{Get "" $tlsConfiguration "/certificate/certfile"}}""" + keyFile = """{{Get "" $tlsConfiguration "/certificate/keyfile"}}""" + +{{end}} `) func templatesKvTmplBytes() ([]byte, error) {