gin支持prometheus

viper监控文件变化出现两次事件

妙音 posted @ 2022年9月17日 20:03 in golang with tags viper golang , 321 阅读
 
问题描述
 
监控配置文件变化,如果内容发生了修改,需要及时加载. 使用viper监控文件变化发现了, 对文件修改一次,会出发两次事件.
 

示例代码

 
viper.OnConfigChange(func(e fsnotify.Event) {
    if e.Op & fsnotify.Write != 0 {
        fmt.Println("Config file changed:", e.Name)
    }
})
viper.WatchConfig()
 

推测原因

 
* 检查viper的源码是否存在bug?
 
未发现异常
 
* 两次变化viper读到的内容返回值是否不一样? 
 
发现viper.AllKeys()返回值不一样, 一次为空, 一次正常.
 
* 换一个电脑试试?
 
发现了在公司办公电脑出现,家里电脑不会出现。
 

解决办法

 
//使用AllKeys进行过滤
viper.OnConfigChange(func(e fsnotify.Event) {
	if e.Op & fsnotify.Write != 0 && viper.AllKeys()>0{
		fmt.Println("Config file changed:", e.Name)
	}
})
viper.WatchConfig()
 
 

总结

 
公司的办公电脑安装了文件加密软件。我估摸着是它搞了个什么鬼.
 
 
 
 
 
Avatar_small
NCERT Mathematics Qu 说:
2022年9月24日 00:18

Mathematics helps us understand the world and provides an effective way of building mental discipline. Math encourages logical reasoning, critical thinking, creative thinking, abstract or spatial thinking, problem-solving ability, and even effective communication. NCERT has introduced the solved question bank with sample paper suggestions for all topics of maths along with solutions. problem-solving ability, NCERT Mathematics Question Paper Class 9 and even effective communication. NCERT has introduced the solved question bank with sample paper suggestions for all topics of maths along with solutions.

Avatar_small
johny 说:
2022年10月01日 20:37

Thanks for sharing the post.. parents are worlds best person in each lives of individual..they need or must succeed to sustain needs of the family. Why inventors turn to experts like InventHelp

Avatar_small
Jacksin 说:
2022年10月03日 13:33

This service runs a plagiarism check on every single piece of writing released to our clients.
Writing tasks are very demanding and often cause imbalance between personal and educational spheres.
That is why numerous students require assistance from a professional essay writing service every day.

Avatar_small
ZOHAIB MALIK 说:
2022年10月13日 02:25

Lake had written involved in exact same issue, Lake can provide the hyperlink into the page. youtube downloader

Avatar_small
da 说:
2022年10月18日 13:50

PEAKERR provides best smm panel Services & cheap smm panel Services In The World. For Youtube Views Panel, TikTok Services Panel, Facebook Services Panel, Instagram Services Panel, And Many More, We Are Providing All Services At Cheap Rates For Reseller SMM Panels. Resell Our SMM Services And Make Money Online. We Have Many Free SMM Panel Services & Give You Some Test Funds For Check Our Services Quality. We Always Try to Provide High-Quality Services At a Cheap Rate. Check: https://peakerr.com/

Avatar_small
Johny 说:
2022年10月20日 14:01

Het strand brengt het beste in iedereen naar boven! Ga met elkaar even helemaal uit je dagelijkse omgeving. Van fysieke activiteiten tot juist tactische activiteiten en denkspellen. Het is écht geschikt voor iedereen! Om dan de dag af te sluiten in de zomer met een heerlijke BBQ of feestavond aan het strand. Stranduitjes aan de Noordhollandse en zuidhollandse stranden

Avatar_small
바카라사이트 说:
2022年10月26日 16:59

This is such a great post, and was thinking much the same myself. Another great update. 바카라사이트

Avatar_small
Johny 说:
2022年10月26日 23:35

Thanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing... driving directions to the closest grocery store

Avatar_small
FAKE NEW SOUTH WALES 说:
2022年10月27日 01:40

This is also a very good post which I really enjoyed reading. It is not every day that I have the possibility to see something like this..

Avatar_small
Johny 说:
2022年10月29日 00:41

These you will then see the most important thing, the application provides you a website a powerful important internet page: แทงบอล

Avatar_small
johny 说:
2022年10月29日 15:37

The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface. แทงบอล

Avatar_small
Facts 说:
2022年10月29日 17:07

GK Digest: GK Quiz for General Knowledge, General Studies, Current Affairs and Aptitude with Interesting Questions for APPSC, Facts TSPSC, UPSC, SSC, Banking / IBPS, IAS, NTSE, CLAT, Railways, NDA, CDS, Judiciary, UPPSC, RPSC, GPSC, MPSC, MPPSC and other states civil services/government Competitive Exams in Telugu.

Avatar_small
Johny 说:
2022年10月30日 23:25

Thank you for the update, very nice site.. evolutionary astrologer

Avatar_small
casinohelper 说:
2022年11月01日 02:20

All online casinos offer clients great bonuses on first deposits and for setting up a new account.

The reason that online casinos offer these benefits is that they lack the enticement that comes with a physical casino’s glitzy interiors, alcoholic drinks, and chimes throughout the building.

Avatar_small
Foreign Banks in Ind 说:
2022年11月02日 16:49

Local and foreign investments measure a country’s economic growth. India is an upcoming, fast-growing economic hub. With thousands of foreign investors from different sectors. India Banks among the sixth-largest consumer market and best in economic progress. List of Foreign Banks in India The country attracts foreign direct investment (FDI) working in various banking and financial sectors. All foreign banks in India play a significant role. They provide financial and insurance services to everyone without discrimination.

Avatar_small
Johny 说:
2022年11月03日 14:14

It is somewhat fantastic, and yet check out the advice at this treat. Fenny TObaku Denpasar

Avatar_small
johny 说:
2022年11月03日 16:00

I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing. seo company orange county

Avatar_small
YSR Bima Scheme Appl 说:
2022年11月03日 17:24

The YSR Bima scheme is developed to help families who lose their family breadwinner to death by accident or disability. The insurance will benefit the families of casual workers and poor state residents. YSR Bima Scheme Apply Online The government has assigned Rs.510 Crores to cater for more than 1.14 crore families in AP state. The government will deposit Rs. 1.5 lakhs in the beneficiary’s Bank account within 15 days. They will also receive Rs—10,000 as immediate financial relief.

Avatar_small
Johny 说:
2022年11月18日 20:45

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work click here

Avatar_small
Johny 说:
2022年11月20日 02:39

Wow, cool post. I'd like to write like this too - taking time and real hard work to make a great article... but I put things off too much and never seem to get started. Thanks though. blc2 powder

Avatar_small
johny 说:
2022年11月21日 23:23 In this case you will begin it is important, it again produces a web site a strong significant internet site: Agen Joker123
Avatar_small
Johny 说:
2022年11月22日 21:28

Mmm.. estimable to be here in your report or notify, whatever, I repute I should moreover process strong for my have website want I play some salubrious further updated busy in your location. Cheap kashmir packages

Avatar_small
jackseo 说:
2022年11月25日 03:37

I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. bergara b14 hunter


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter