当前位置:网站首页>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
边栏推荐
- How to write plug-in code of small program mall system? How to use code to check whether the plug-in is successfully added?
- Open source a set of minimalist front and rear end separation project scaffold
- 应用层软件开发教父教你如何重构,资深程序员必备专业技能
- [byte jumps, autumn recruitment Posts open] ohayoo! Don't leave after school, I want to ask you to play games!!!
- VARCHART XGantt如何在日历上表示工作日
- Configuration of AP hotspot on xunwei-imx6ull development board
- September 3, 2020: naked writing algorithm: loop matrix traversal.
- 消防器材RFID固定资产管理系统
- What grammar is it? ]
- Experiment one
猜你喜欢
Application of UHF RFID medical blood management system
Common mathematical basic formulas of recursive and backtracking algorithms
2020-08-14:数据任务的执行引擎用的哪些?
The native API of the future trend of the front end: web components
上海巨微专用蓝牙广播芯片
Js字符串-String字符串对象方法
What kind of music do you need to make for a complete game?
Exclusive interview of guests at | 2020 PostgreSQL Asia Conference: Wang Tao
2020-08-18:介绍下MR过程?
Application layer software development Godfather teaches you how to refactor, senior programmers must professional skills
随机推荐
A good thing for working people -- to temper the will of iron and steel requires such an efficient computer
Stm32f030f4p6 compatible with smart micro mm32f031f4p6
image operating system windows cannot be used on this platform
2020-09-04: do you understand the function call convention?
How to start the hidden preferences in coda 2 on the terminal?
2020-08-14:数据任务的执行引擎用的哪些?
Count the number of project code lines
The use of Xunwei imx6 development board device tree kernel menuconfig
2020 database technology conference helps technology upgrade
What grammar is it? ]
Benefits and functions of auto maintenance app development
All the way, I was forced to talk about C code debugging skills and remote debugging
August 18, 2020: introduce Mr process?
如何才能快速正确的部署甘特图
How much disk space does a file of 1 byte actually occupy
Common syntax corresponding table of mongodb and SQL
The memorandum model of behavior model
DC-1 target
C and C / C + + mixed programming series 5 - GC collaboration of memory management
NAND FLASH的接口控制设计