Skip to content

Commit

Permalink
Fix whitespace in nginx templates (#597)
Browse files Browse the repository at this point in the history
The nginx templates were hard to read due to excessive whitespacing in the templates. It's not perfect, but these changes should clean things up quite a bit.
  • Loading branch information
sjberman authored Apr 28, 2023
1 parent 6befb1d commit f73e994
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
24 changes: 12 additions & 12 deletions internal/nginx/config/servers_template.go
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
package config

var serversTemplateText = `
{{ range $s := . }}
{{ if $s.IsDefaultSSL }}
{{ range $s := . -}}
{{ if $s.IsDefaultSSL -}}
server {
listen 443 ssl default_server;
ssl_reject_handshake on;
}
{{ else if $s.IsDefaultHTTP }}
{{- else if $s.IsDefaultHTTP }}
server {
listen 80 default_server;
default_type text/html;
return 404;
}
{{ else }}
{{- else }}
server {
{{ if $s.SSL }}
{{- if $s.SSL }}
listen 443 ssl;
ssl_certificate {{ $s.SSL.Certificate }};
ssl_certificate_key {{ $s.SSL.CertificateKey }};
if ($ssl_server_name != $host) {
return 421;
}
{{ end }}
{{- end }}
server_name {{ $s.ServerName }};
{{ range $l := $s.Locations }}
location {{ $l.Path }} {
{{ if $l.Internal }}
{{ if $l.Internal -}}
internal;
{{ end }}
{{ if $l.Return }}
{{- if $l.Return -}}
return {{ $l.Return.Code }} "{{ $l.Return.Body }}";
{{ end }}
{{ if $l.HTTPMatchVar }}
{{- if $l.HTTPMatchVar -}}
set $http_matches {{ $l.HTTPMatchVar | printf "%q" }};
js_content httpmatches.redirect;
{{ end }}
{{ if $l.ProxyPass }}
{{- if $l.ProxyPass -}}
proxy_set_header Host $host;
proxy_pass {{ $l.ProxyPass }}$request_uri;
{{ end }}
{{- end }}
}
{{ end }}
}
{{ end }}
{{- end }}
{{ end }}
server {
listen unix:/var/lib/nginx/nginx-502-server.sock;
Expand Down
13 changes: 7 additions & 6 deletions internal/nginx/config/split_clients_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package config
var splitClientsTemplateText = `
{{ range $sc := . }}
split_clients $request_id ${{ $sc.VariableName }} {
{{ range $d := $sc.Distributions }}
{{ if eq $d.Percent "0.00" }}
{{- range $d := $sc.Distributions }}
{{- if eq $d.Percent "0.00" }}
# {{ $d.Percent }}% {{ $d.Value }};
{{ else }}
{{- else }}
{{ $d.Percent }}% {{ $d.Value }};
{{ end }}
{{ end }}
{{- end }}
{{- end }}
}
{{ end }}`
{{ end }}
`
5 changes: 3 additions & 2 deletions internal/nginx/config/upstreams_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ upstream {{ $u.Name }} {
random two least_conn;
{{ range $server := $u.Servers }}
server {{ $server.Address }};
{{ end }}
{{- end }}
}
{{ end }}`
{{ end }}
`

0 comments on commit f73e994

Please sign in to comment.