diff --git a/httppoll.go b/httppoll.go index 51ce254..787d8f3 100644 --- a/httppoll.go +++ b/httppoll.go @@ -18,9 +18,9 @@ func Poll(url string) { data, err := ioutil.ReadAll(resp.Body) if err != nil { ErrorinPoll(url) - resp.Body.Close() + _ = resp.Body.Close() } else { - resp.Body.Close() + _ = resp.Body.Close() var parsed V13 err = json.Unmarshal(data, &parsed) @@ -30,12 +30,12 @@ func Poll(url string) { if parsed.State.Open != nil { open := parsed.State.Open.(bool) if open { - spacestates[url] = Open + SetSpaceState(url, Open) } else { - spacestates[url] = Close + SetSpaceState(url, Close) } } else { - spacestates[url] = Unknown + SetSpaceState(url, Unknown) } } @@ -47,6 +47,12 @@ func Poll(url string) { func ErrorinPoll(url string) { if spacestates[url] != Unknown { - spacestates[url] = Outdated + SetSpaceState(url, Outdated) } } + +func SetSpaceState(url string, s State) { + lock.Lock() + spacestates[url] = s + lock.Unlock() +} diff --git a/setup.go b/setup.go index c1ce58a..809036f 100644 --- a/setup.go +++ b/setup.go @@ -6,6 +6,7 @@ import ( yaml "gopkg.in/yaml.v2" io "io/ioutil" "net/http" + "sync" "time" ) @@ -14,6 +15,7 @@ var conffile = "conf.yml" var sleeptime time.Duration = 60000000000 // nanoseconds var leds [][]string var spacestates map[string]State +var lock = sync.RWMutex{} func SetConf(s string) { conffile = s