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