improved Logging

This commit is contained in:
Malte Münch 2020-01-31 15:42:04 +01:00
parent 88b94d10be
commit 94d03e1c2f
2 changed files with 7 additions and 7 deletions

View File

@ -8,16 +8,15 @@ import (
"time"
)
func Poll(url string) {
func Poll(url string, led int) {
for true {
resp, err := http.Get(url)
if err != nil {
ErrorinPoll(url)
fmt.Println(err.Error())
ErrorPoll(url, err, led)
} else {
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
ErrorinPoll(url)
ErrorPoll(url, err, led)
_ = resp.Body.Close()
} else {
_ = resp.Body.Close()
@ -25,7 +24,7 @@ func Poll(url string) {
var parsed V13
err = json.Unmarshal(data, &parsed)
if err != nil {
ErrorinPoll(url)
ErrorPoll(url, err, led)
} else {
if parsed.State.Open != nil {
open := parsed.State.Open.(bool)
@ -45,10 +44,11 @@ func Poll(url string) {
}
}
func ErrorinPoll(url string) {
func ErrorPoll(url string, err error, led int) {
if spacestates[url] != Unknown {
SetSpaceState(url, Outdated)
}
fmt.Println("LED", led, err.Error())
}
func SetSpaceState(url string, s State) {

View File

@ -43,7 +43,7 @@ func Start() {
for i := 0; i < len(leds); i++ {
for j := 0; j < len(leds[i]); j++ {
spacestates[leds[i][j]] = Unknown
go Poll(leds[i][j])
go Poll(leds[i][j], i)
}
}
fmt.Println("Loaded", len(leds), "LED-configs and", len(spacestates), "spaces.")