我在领事模板中使用以下模板:
{{ range services }}
{{ $server_name := .Name | replaceAll "_" "." }}
{{ range .Tags }}
{{ if . | regexMatch "server_name=" }}
# found matching server_name in {{ . }}
{{ $server_name := . | regexReplaceAll ".*=" "" }}
{{ end }}
{{ end }}
# server_name = {{ $server_name }}
acl host_{{ .Name }} hdr(host) -i {{ $server_name }}
use_backend {{ .Name }}_backend if host_{{ .Name }}
{{ end }}
产生
# found matching server_name in server_name=geoserver.hello.org
# server_name = geoserver.dev.hello.org
acl host_geoserver_dev_hello_org hdr(host) -i geoserver.dev.hello.org
use_backend geoserver_dev_hello_org_backend if host_geoserver_dev_hello_org
在哪里.Name
并且geoserver_dev_hello_org
有一个server_name=geoserver.hello.org
标签。我希望在.Tags
范围循环结束时,$server_name
应该有 value geoserver.hello.org
,但它仍然具有原始值geoserver.dev.hello.org
。
如何使循环覆盖$server_name
(并在找到值时退出循环)?