add wg
This commit is contained in:
8
main.go
8
main.go
@@ -8,12 +8,14 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
shellyFlag = flag.String("s", "", "list shelly ips, comma seperated")
|
||||
debugFlag = flag.Bool("d", false, "enable debug mode")
|
||||
wg sync.WaitGroup
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -102,6 +104,8 @@ func main() {
|
||||
log.Fatal("no shelly ips specified")
|
||||
}
|
||||
|
||||
wg := new(sync.WaitGroup)
|
||||
|
||||
for _, ip := range strings.Split(*shellyFlag, ",") {
|
||||
go func() {
|
||||
err := checkShelly(ip)
|
||||
@@ -110,9 +114,13 @@ func main() {
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func checkShelly(ip string) error {
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
log.Infof("shelly worker %s started", ip)
|
||||
|
||||
for {
|
||||
|
Reference in New Issue
Block a user