borrar ip poller

se rompe en el contenedor por falta de `ip` y no funciona realmente
This commit is contained in:
Cat /dev/Nulo 2023-07-07 13:59:06 -03:00
parent 66c7071605
commit dfeee0ca89

32
main.go
View file

@ -4,8 +4,6 @@ import (
"context" "context"
"log" "log"
"os" "os"
"os/exec"
"strings"
"sync" "sync"
"time" "time"
) )
@ -24,7 +22,6 @@ func main() {
refr := make(refreshChan) refr := make(refreshChan)
errch := make(chan error) errch := make(chan error)
go poller(config.Every, refr) go poller(config.Every, refr)
go ipPoller(refr, errch)
for { for {
select { select {
case reason := <-refr: case reason := <-refr:
@ -54,34 +51,7 @@ func main() {
func poller(every int, refr refreshChan) { func poller(every int, refr refreshChan) {
for { for {
time.Sleep(time.Duration(every) * time.Minute)
refr <- "poll" refr <- "poll"
} time.Sleep(time.Duration(every) * time.Minute)
}
func ipPoller(refr refreshChan, errch chan error) {
var lastWatched string
for {
cmd := exec.Command("ip", "address")
out, err := cmd.Output()
if err != nil {
errch <- err
return
}
var addrs string
lines := strings.Split(string(out), "\n")
for _, line := range lines {
prefix := " inet "
if strings.Index(line, prefix) == 0 {
last := strings.Index(line[len(prefix):], "/")
ip := line[len(prefix) : len(prefix)+last]
addrs = addrs + ip + "/"
}
}
if addrs != lastWatched {
refr <- "ip changed"
lastWatched = addrs
}
time.Sleep(time.Duration(2) * time.Second)
} }
} }