forked from mamu/spacepanel_aggregator
improved Logging
This commit is contained in:
parent
88b94d10be
commit
94d03e1c2f
12
httppoll.go
12
httppoll.go
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue