consul - 查询Consul服务目录时如何检索有限数量的IP
问题描述
有没有办法从 Consul 服务目录中只检索 3 个 IP?
{{if service 'web' 'passing'}}
"{{range $index, $service := service 'web'}}{{if ne $index 0}},{{end}}{{.Address}}{{end}}"
上面的代码获取所有通过 web 服务检查的逗号分隔的 IP(我有 100 个 IP)。我只需要前 3 个 IP。
-W
解决方案
{{range $index, $service := service "web"}}{{if gt $index 3}}{{.Address}}:{{ .Port }},{{end}}{{end}}
应该这样做。
推荐阅读
- eclipse - Eclipse EditorPart 保存在 partDeactivated 上
- c# - Recurring Job异步调用WebApi,然后在回调方法中修改Hangfire Job的状态
- javascript - Nuxtjs 结合 spa 预渲染
- c++ - 在 Qt 中显示对话框的密码
- spring-boot - 在 Angular 6 中停止 addEventListener
- sql - 将 JSON 字符串转换为十进制的问题
- postgresql - 在 postgresql 执行语句中使用变量
- spring - 客户端发现后 Eureka Server 停止工作
- java - 在 Spring Boot 应用程序中配置 Jackson mixin
- python - 再次使用密钥列表从列表中创建字典