From 9dbb1b4153e6afe89f2e009831e1229865f474ad Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Wed, 28 Dec 2022 00:53:25 +0100 Subject: [PATCH] style: improve template readability --- nginx.tmpl | 75 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 9 deletions(-) diff --git a/nginx.tmpl b/nginx.tmpl index aeb0b2b..f2b5688 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -107,7 +107,13 @@ upstream {{ .Upstream }} { {{ end }} {{ range $knownNetwork := $networks }} {{ range $containerNetwork := sortObjectsByKeysAsc $container.Networks "Name" }} - {{ if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }} + {{ if (and + (ne $containerNetwork.Name "ingress") + (or + (eq $knownNetwork.Name $containerNetwork.Name) + (eq $knownNetwork.Name "host") + ) + )}} ## Can be connected with "{{ $containerNetwork.Name }}" network {{ if $address }} {{/* If we got the containers from swarm and this container's port is published to host, use host IP:PORT */}} @@ -289,13 +295,23 @@ server { {{ if eq $nPaths 0 }} # {{ $host }} - {{ template "upstream" (dict "Upstream" $upstream_name "Containers" $containers "Networks" $CurrentContainer.Networks "Debug" $debug_all) }} + {{ template "upstream" (dict + "Upstream" $upstream_name + "Containers" $containers + "Networks" $CurrentContainer.Networks + "Debug" $debug_all + )}} {{ else }} {{ range $path, $containers := $paths }} {{ $sum := sha1 $path }} {{ $upstream := printf "%s-%s" $upstream_name $sum }} # {{ $host }}{{ $path }} - {{ template "upstream" (dict "Upstream" $upstream "Containers" $containers "Networks" $CurrentContainer.Networks "Debug" $debug_all) }} + {{ template "upstream" (dict + "Upstream" $upstream + "Containers" $containers + "Networks" $CurrentContainer.Networks + "Debug" $debug_all + )}} {{ end }} {{ end }} @@ -340,7 +356,12 @@ server { "AccessLog" $access_log }} -{{ $is_https := (and (ne $https_method "nohttps") (ne $cert "") (exists (printf "/etc/nginx/certs/%s.crt" $cert)) (exists (printf "/etc/nginx/certs/%s.key" $cert))) }} +{{ $is_https := (and + (ne $https_method "nohttps") + (ne $cert "") + (exists (printf "/etc/nginx/certs/%s.crt" $cert)) + (exists (printf "/etc/nginx/certs/%s.key" $cert)) +)}} {{ if $is_https }} @@ -412,7 +433,15 @@ server { {{/* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external" */}} {{ $network_tag := or (first (groupByKeys $containers "Env.NETWORK_ACCESS")) "external" }} - {{ template "location" (dict "Path" "/" "Proto" $proto "Upstream" $upstream_name "Host" $host "VhostRoot" $vhost_root "Dest" "" "NetworkTag" $network_tag) }} + {{ template "location" (dict + "Path" "/" + "Proto" $proto + "Upstream" $upstream_name + "Host" $host + "VhostRoot" $vhost_root + "Dest" "" + "NetworkTag" $network_tag + )}} {{ else }} {{ range $path, $container := $paths }} {{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost-vpath, falling back to "http" */}} @@ -423,7 +452,15 @@ server { {{ $sum := sha1 $path }} {{ $upstream := printf "%s-%s" $upstream_name $sum }} {{ $dest := (or (first (groupByKeys $container "Env.VIRTUAL_DEST")) "") }} - {{ template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "VhostRoot" $vhost_root "Dest" $dest "NetworkTag" $network_tag) }} + {{ template "location" (dict + "Path" $path + "Proto" $proto + "Upstream" $upstream + "Host" $host + "VhostRoot" $vhost_root + "Dest" $dest + "NetworkTag" $network_tag + )}} {{ end }} {{ if (not (contains $paths "/")) }} location / { @@ -455,7 +492,15 @@ server { {{/* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external" */}} {{ $network_tag := or (first (groupByKeys $containers "Env.NETWORK_ACCESS")) "external" }} - {{ template "location" (dict "Path" "/" "Proto" $proto "Upstream" $upstream_name "Host" $host "VhostRoot" $vhost_root "Dest" "" "NetworkTag" $network_tag) }} + {{ template "location" (dict + "Path" "/" + "Proto" $proto + "Upstream" $upstream_name + "Host" $host + "VhostRoot" $vhost_root + "Dest" "" + "NetworkTag" $network_tag + )}} {{ else }} {{ range $path, $container := $paths }} {{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost-vpath, falling back to "http" */}} @@ -466,7 +511,15 @@ server { {{ $sum := sha1 $path }} {{ $upstream := printf "%s-%s" $upstream_name $sum }} {{ $dest := (or (first (groupByKeys $container "Env.VIRTUAL_DEST")) "") }} - {{ template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "VhostRoot" $vhost_root "Dest" $dest "NetworkTag" $network_tag) }} + {{ template "location" (dict + "Path" $path + "Proto" $proto + "Upstream" $upstream + "Host" $host + "VhostRoot" $vhost_root + "Dest" $dest + "NetworkTag" $network_tag + )}} {{ end }} {{ if (not (contains $paths "/")) }} location / { @@ -476,7 +529,11 @@ server { {{ end }} } -{{ if (and (not $is_https) (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }} +{{ if (and + (not $is_https) + (exists "/etc/nginx/certs/default.crt") + (exists "/etc/nginx/certs/default.key") +)}} server { {{ template "server_config" (deepCopy $baseServerConfig | mustMerge (dict "SSL" true