27 lines
685 B
Go
27 lines
685 B
Go
![]() |
package api
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
"io/ioutil"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
func FetchArea(area int) (string, error) {
|
||
|
tUrl := fmt.Sprintf("https://113.webclimber.de/de/trafficlight?callback=WebclimberTrafficlight.insertTrafficlight&key=mu4Gk2NXGBfUU30McdwEkq18SDks2xDB&hid=113&container=trafficlightContainer&type=2&area=%v", area)
|
||
|
tResponse, err := http.Get(tUrl)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
defer tResponse.Body.Close()
|
||
|
if tResponse.StatusCode / 100 != 2 {
|
||
|
return "", errors.New(fmt.Sprintf("request returned unexpected return code: %v", tResponse.Status))
|
||
|
}
|
||
|
|
||
|
tBody, err := ioutil.ReadAll(tResponse.Body)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
return string(tBody[:]), nil
|
||
|
}
|