当前位置:网站首页>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
边栏推荐
- File download manager realized by electron
- August 24, 2020: what are small documents? What's wrong with a lot of small files? How to solve many small files? (big data)
- C language I blog assignment 03
- What kind of music do you need to make for a complete game?
- The essence of transaction and the principle of deadlock
- Open source a set of minimalist front and rear end separation project scaffold
- STM32F030K6T6兼容替换灵动MM32F031K6T6
- 迅为-iMX6ULL开发板上配置AP热点
- QT audio and video development 46 video transmission UDP version
- Windows 10 Bluetooth management page 'add Bluetooth or other devices' option click no response solution
猜你喜欢
Application of UHF RFID medical blood management system
The use of Xunwei imx6 development board device tree kernel menuconfig
August 30, 2020: naked write algorithm: the nearest common ancestor of two nodes in a binary tree.
消防器材RFID固定资产管理系统
Reserved battery interface, built-in charge and discharge circuit and electricity meter, quickly help easily handle hand-held applications
How to write plug-in code of small program mall system? How to use code to check whether the plug-in is successfully added?
August 14, 2020: what are the execution engines for data tasks?
上海巨微专用蓝牙广播芯片
Mobile pixel adaptation scheme
Nodejs中使用jsonwebtoken(JWT)生成token的场景使用
随机推荐
[graffiti Internet of things footprints] panoramic introduction of graffiti cloud platform
STM32F030K6T6兼容替换灵动MM32F031K6T6
How to create an interactive kernel density chart
The role of theme music in games
The Interpreter pattern of behavior pattern
How to write plug-in code of small program mall system? How to use code to check whether the plug-in is successfully added?
Zhou Jie: database system of East China Normal University
All the way, I was forced to talk about C code debugging skills and remote debugging
移动端像素适配方案
A good thing for working people -- to temper the will of iron and steel requires such an efficient computer
Python 100 cases
2020-08-20:GO语言中的协程与Python中的协程的区别?
vue3 新特性
STM32F030F4P6兼容灵动微MM32F031F4P6
A concise tutorial for Nacos, ribbon and feign
Web API interface design: swaggerui document / unified response format / unified exception handling / unified authority verification
How to make characters move
Ora-02292: complete constraint violation (midbjdev2.sys_ C0020757) - subrecord found
Utility class functions (continuous update)
心理咨询app开发所具备的优点与功能