我有一些 领事 </跨度> 看起来类似于的节点:
[ { “地址”:“127.0.0.1”, “节点”:“foo”, “ServiceAddress”:“”, “ServiceName”:“api service”production.api“}}{{。地址}}{{结束}}
但我怎样才能过滤我的服务 领事 </跨度> - 一次用两个标签模板?
这就是我在haproxy中使用服务标签的方式,因此可以在nginx中完成类似的操作
{{ range $tag, $services := service "some-service" | byTag }} backend some-service-{{ $tag }} {{ if eq $tag "some_tag" }} .... {{ end }} ... {{ range $services }} server {{.Address}}-{{.Port}} {{.Address}}:{{.Port}} check downinter 3s inter 2000 fall 3 maxconn 100 check cookie {{.ID}} weight 1 {{ end }} {{ end }}
从consul-template v0.11.1开始,您可以使用 contains 运营商:
contains
{{range service "production.api"}} {{if .Tags | contains "nonblocking"}} {{.Address}} {{end}} {{end}}
如果您使用的是旧版本,则可以使用Go:
{{range service "api"}} {{if and (.Tags.Contains "nonblocking") (.Tags.Contains "production")}} {{end}} {{end}}
也可以看看: https://github.com/hashicorp/consul-template/issues/260