【发布时间】:2016-11-29 04:30:43
【问题描述】:
有谁知道如何将 consul 中的字符串连接到 consul-template 中?
如果我在 Consul 中注册了服务 'foo'
{
"Node": "node1",
"Address": "192.168.0.1",
"Port": 3333
},
{
"Node": "node2",
"Address": "192.168.0.2",
"Port": 4444
}
我希望 consul-template 生成以下行:
servers=192.168.0.1:3333,192.168.0.2:4444/bogus
以下尝试不起作用,因为它留下了尾随逗号,
servers={{range service "foo"}}{{.Address}}{{.Port}},{{end}}/bogus
# renders
servers=192.168.0.1:3333,192.168.0.2:4444,/bogus
# What I actually want
servers=192.168.0.1:3333,192.168.0.2:4444/bogus
我知道 consul-template 使用 golang 模板语法,但我根本无法弄清楚使这个工作正常的语法。我可能应该使用领事模板的join,但我如何将.Address 和.Port 都传递给join?这只是一个简单的例子,我没有故意使用索引,因为服务的数量可能超过两个。有什么想法吗?
【问题讨论】:
标签: templates go consul consul-template