This commit is contained in:
@@ -27,7 +27,7 @@ var wrJSONCache = make(map[string]*wrJSONEntry)
|
||||
|
||||
// Get will fetch an url and returns reponse
|
||||
func Get(url string, opts interface{}) (resp *http.Response, err error) {
|
||||
logger.Log.Noticef("requesting url via GET %s", url)
|
||||
logger.N("requesting url via GET %s", url)
|
||||
|
||||
progress.IncrTotal("web request")
|
||||
progress.DescribeCurrent("web request", url)
|
||||
@@ -41,20 +41,16 @@ func GetJSON(url string) interface{} {
|
||||
cached := wrJSONCache[url]
|
||||
if cached == nil {
|
||||
resp, err := Get(url, nil)
|
||||
if err != nil {
|
||||
logger.Log.Panicf("could not get url '%s': %s", url, err)
|
||||
}
|
||||
logger.Eexit(err, "could not get url '%s'", url)
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
logger.Log.Panicf("could not read body from url '%s': %s", url, err)
|
||||
}
|
||||
logger.Eexit(err, "could not read body from url '%s'", url)
|
||||
|
||||
logger.Log.Debugf("output from url '%s':\n%s", url, string(body))
|
||||
logger.D("output from url '%s':\n%s", url, string(body))
|
||||
|
||||
if resp.StatusCode >= 400 {
|
||||
logger.Log.Panicf("bad status '%d - %s' from url '%s'", resp.StatusCode, resp.Status, url)
|
||||
logger.Exit("bad status '%d - %s' from url '%s'", resp.StatusCode, resp.Status, url)
|
||||
}
|
||||
|
||||
contentType := resp.Header.Get("Content-Type")
|
||||
@@ -62,7 +58,7 @@ func GetJSON(url string) interface{} {
|
||||
if strings.Contains(contentType, "json") {
|
||||
|
||||
} else {
|
||||
logger.Log.Panicf("is not json '%s' from url '%s'", contentType, url)
|
||||
logger.Exit("is not json '%s' from url '%s'", contentType, url)
|
||||
}
|
||||
|
||||
cached = new(wrJSONEntry)
|
||||
@@ -77,7 +73,7 @@ func GetJSON(url string) interface{} {
|
||||
if err == nil {
|
||||
cached.data = jsonArrayMap
|
||||
} else {
|
||||
logger.P("could not read json from '%s': invalid type", url)
|
||||
logger.Exit("could not read json from '%s': invalid type", url)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user