Skip to content

Instantly share code, notes, and snippets.

@JackyCZJ
Last active July 2, 2020 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JackyCZJ/e502e3068e7eadd59fc2810740167abc to your computer and use it in GitHub Desktop.
Save JackyCZJ/e502e3068e7eadd59fc2810740167abc to your computer and use it in GitHub Desktop.
looper
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