setear records al mismo tiempo
This commit is contained in:
parent
309386d21b
commit
574dce2794
1 changed files with 14 additions and 7 deletions
11
main.go
11
main.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,17 +31,23 @@ func main() {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(10)*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(10)*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
log.Printf("Running because of %s", reason)
|
log.Printf("Running because of %s", reason)
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(len(config.Domains))
|
||||||
for _, d := range config.Domains {
|
for _, d := range config.Domains {
|
||||||
|
go func(d Domain, wg *sync.WaitGroup) {
|
||||||
record, err := d.NameServer.SetRecord(ctx, d.Name, config.Ip)
|
record, err := d.NameServer.SetRecord(ctx, d.Name, config.Ip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
continue
|
// TODO: Reportar errores
|
||||||
|
return
|
||||||
}
|
}
|
||||||
log.Printf("[%s] Set to %s", d.Name, record)
|
log.Printf("[%s] Set to %s", d.Name, record)
|
||||||
|
wg.Done()
|
||||||
|
|
||||||
|
}(d, &wg)
|
||||||
}
|
}
|
||||||
case err := <-errch:
|
case err := <-errch:
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue