当前位置:网站首页>confd
confd
2020-11-06 22:33:00 【waynehu】
confd
{{/*
使用lsdir方法,读取(可以认为)/services/web目录下的子目录,也就是返回cust1和cust2这两个。
并开始一个大循环,第1次循环,$dir等于cust1 ,第2次循环,$dir等于cust2
*/}}
{{range $dir := lsdir "/services/web"}}
upstream {{base $dir}} {
{{/*
使用printf方法,合成一个字符串,%s的部分用$dir来替代。
合成之后的新字符串赋值给$custdir,第一次应该是"/services/web/cust1/*"
使用gets查找key为"/services/web/cust1/*"的值,因为用到了*,会查出多个值,所以用到gets而不是get
每个值都会进入小循环,并用json进行解析(这里注意etcdctl put进去的value,必须符合json格式,否则在这里解析会失败)
解析完的内容复制给$data,然后就可以用了
*/}}
{{$custdir := printf "/services/web/%s/*" $dir}}{{range gets $custdir}}
server {{$data := json .Value}}{{$data.IP}}:{{$data.PORT}};
{{end}}
}
server {
server_name {{base $dir}}.example.com;
location / {
proxy_pass {{base $dir}};
}
}
{{end}}
./etcdctl put /services/web/cust1/1 '{"IP": "10.0.0.1","PORT":"81"}'
./etcdctl put /services/web/cust1/2 '{"IP": "10.0.0.2","PORT":"82"}'
./etcdctl put /services/web/cust1/3 '{"IP": "10.0.0.3","PORT":"83"}'
./etcdctl put /services/web/cust2/1 '{"IP": "10.0.0.4","PORT":"84"}'
./etcdctl put /services/web/cust2/2 '{"IP": "10.0.0.5","PORT":"85"}'
./etcdctl put /services/web/cust2/3 '{"IP": "10.0.0.6","PORT":"86"}'
https://github.com/kelseyhightower/confd/blob/master/docs/templates.md
版权声明
本文为[waynehu]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/943306/blog/4706338
边栏推荐
- Erd-online free online database modeling tool
- Qt音视频开发46-视频传输UDP版
- 小程序商城系统插件代码该如何写?怎么用代码检查添加插件是否成功?
- August 30, 2020: naked write algorithm: the nearest common ancestor of two nodes in a binary tree.
- Stickinengine architecture 11 message queue
- 细数软件工程----各阶段必不可少的那些图
- A concise tutorial for Nacos, ribbon and feign
- 2020年新规,微信封号怎么快速解除?
- 高速公路二维码定位报警系统
- 20 XR projects roadshows, nearly 20 capital institutions attended! We sincerely invite you to attend the 2020 qcomm XR eco Partner Conference
猜你喜欢
Utility class functions (continuous update)
Empty test suite appears in JUnit test
Using JSON webtoken (JWT) to generate token in nodejs
WebAPI接口设计:SwaggerUI文档 / 统一响应格式 / 统一异常处理 / 统一权限验证
Practice of Xiaoxiong school development board: real equipment access of smart street lamp sandbox experiment
How to make characters move
NAND FLASH的接口控制设计
Benefits and functions of auto maintenance app development
JVM class loading mechanism
磁存储芯片STT-MRAM的特点
随机推荐
Introduction to Huawei cloud micro certification examination
应用层软件开发教父教你如何重构,资深程序员必备专业技能
The 4th China BIM (digital construction) manager Summit Forum will be held in Hangzhou in 2020
The isolation level of transaction and its problems
Design of NAND flash interface control
The first choice for lightweight GPU applications is the NVIDIA vgpu instance launched by Jingdong Zhilian cloud
How to make characters move
Exclusive interview of guests at | 2020 PostgreSQL Asia Conference: Wang Tao
Big data processing black Technology: revealing the parallel computing technology of Pb level data warehouse gaussdb (DWS)
JVM class loading mechanism
2020-08-19:TCP是通过什么机制保障可靠性的?
NAND FLASH的接口控制设计
2020-08-17:详细说下数据倾斜怎么解决?
The Interpreter pattern of behavior pattern
Windows 10 蓝牙管理页面'添加蓝牙或其他设备'选项点击无响应的解决方案
Visual rolling [contrast beauty]
All the way, I was forced to talk about C code debugging skills and remote debugging
高速公路二维码定位报警系统
Js数组-数组的用法全在这里(数组方法的重构、数组的遍历、数组的去重,数组的判断与转换)
汽车维修app开发的好处与功能