This commit is contained in:
2025-03-27 13:30:42 +01:00
parent 13c33e1ff1
commit 72ab5a24a0

View File

@@ -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 {