forked from mamu/spacepanel_aggregator
added Mutex for Mapaccess
This commit is contained in:
parent
3ac7d60864
commit
88b94d10be
18
httppoll.go
18
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()
|
||||
}
|
||||
|
|
2
setup.go
2
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
|
||||
|
|
Loading…
Reference in New Issue