-
-
Save tsenart/3642a68f5e3b7dd2cee3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var sleep time.Duration | |
known := map[string]struct{}{} | |
for { | |
time.Sleep(sleep) | |
ips, _ := readIPs("ips.json") | |
for _, ip := range ips { | |
if _, ok := known[ip]; !ok { | |
known[ip] = struct{}{} | |
doSomething(ip) | |
} | |
} | |
sleep = 3 * time.Second | |
} | |
func readIPs(file string) (ips []string, err error) { | |
if data, err := ioutil.ReadFile(file); err != nil { | |
return nil, err | |
} else if err = json.Unmarshal(data, &ips); err != nil { | |
return nil, err | |
} | |
return ips, err | |
} |
More code? It's strictly less lines of code, no? It's also better encapsulated with the utility function to readIPs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you explain the benefits of this a bit? On first glance this seems to add more code?