当前位置:网站首页>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
边栏推荐
- The native API of the future trend of the front end: web components
- Configuration of AP hotspot on xunwei-imx6ull development board
- How to add modules to nginx image?
- 2020-08-14:数据任务的执行引擎用的哪些?
- 迅为-iMX6ULL开发板上配置AP热点
- Road to simple HTML + JS to achieve the most simple game Tetris
- Why is the LS command stuck when there are too many files?
- image operating system windows cannot be used on this platform
- Stm32f030f4p6 compatible with smart micro mm32f031f4p6
- 2020-08-20: the difference between go and python?
猜你喜欢
Common syntax corresponding table of mongodb and SQL
STM32F030F4P6兼容灵动微MM32F031F4P6
Win7 AppCrash (solution)
Nodejs中使用jsonwebtoken(JWT)生成token的场景使用
The advantages and functions of psychological counseling app
2020-08-15: under what circumstances should data tasks be optimized?
Bluetooth broadcast chip for Shanghai giant micro
Method of code refactoring -- Analysis of method refactoring
Unity performance optimization
September 3, 2020: naked writing algorithm: loop matrix traversal.
随机推荐
超高频RFID医疗血液管理系统应用
JVM class loading mechanism
“非洲用户的付费意愿并不低”——专访四达时代研发总监张亮
2020-08-29: process thread differences, in addition to the inclusion relationship, the underlying details?
2020年新规,微信封号怎么快速解除?
2020-09-04: do you understand the function call convention?
All the way, I was forced to talk about C code debugging skills and remote debugging
Mongo user rights login instruction
A good thing for working people -- to temper the will of iron and steel requires such an efficient computer
Python 100 cases
How much disk space does a new empty file take?
2020-08-17: how to solve data skew in detail?
Novice guidance and event management system in game development
How to add modules to nginx image?
Windows 10 蓝牙管理页面'添加蓝牙或其他设备'选项点击无响应的解决方案
Road to simple HTML + JS to achieve the most simple game Tetris
What are the highlights of Huawei mate 40 series with HMS?
实验一
[graffiti Internet of things footprints] panoramic introduction of graffiti cloud platform
如何使用甘特图图层和筛选器