Last active
July 2, 2020 10:17
-
-
Save JackyCZJ/e502e3068e7eadd59fc2810740167abc to your computer and use it in GitHub Desktop.
looper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
viper.SetDefault("push.frequency", 100) | |
d.timer = time.NewTicker(viper.GetDuration("push.frequency") * time.Millisecond) | |
//Make interface for netInterface we need to watch. | |
for bn := range bCache { | |
if d.InterfaceCache[bn] == nil { | |
inter, err := net.InterfaceByName(bn) | |
if err != nil { | |
return | |
} | |
d.InterfaceCache[bn] = inter | |
} | |
} | |
//start loop. | |
for { | |
select { | |
case <-d.timer.C: | |
//when tick tok , compare it. | |
d.Compare() | |
//hung up goroutine. release cpu. | |
runtime.Gosched() | |
case update := <-d.Update: | |
//received update signal | |
if update { | |
for bn := range bCache { | |
ip, err := d.InterfaceCache[bn].Addrs() | |
if err != nil { | |
return | |
} | |
if len(ip) == 0 { | |
return | |
} | |
d.CacheHash[bn] = string(d.InterfaceCache[bn].MTU) | |
for i := range ip { | |
d.CacheHash[bn] = d.CacheHash[bn] + ip[i].String() | |
} | |
} | |
log.Info("IP Change!") | |
CheckDeviceInfo() | |
} | |
//hung up goroutine. release cpu. | |
runtime.Gosched() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment