Add client timeout and close response immediately.
This commit is contained in:
parent
2f15ad4244
commit
3b4dc324eb
1 changed files with 4 additions and 2 deletions
|
@ -327,13 +327,15 @@ func main() {
|
||||||
}
|
}
|
||||||
req.Header.Set("User-Agent", "pnut-bridge")
|
req.Header.Set("User-Agent", "pnut-bridge")
|
||||||
req.Header.Add("Authorization", "Bearer "+conf.MbToken)
|
req.Header.Add("Authorization", "Bearer "+conf.MbToken)
|
||||||
client := &http.Client{}
|
client := &http.Client{
|
||||||
|
Timeout: 10 * time.Second,
|
||||||
|
}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(">> error on reponse", err)
|
log.Println(">> error on reponse", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
|
resp.Body.Close()
|
||||||
//log.Println("<< ", string([]byte(body)))
|
//log.Println("<< ", string([]byte(body)))
|
||||||
var m []MbMessage
|
var m []MbMessage
|
||||||
jerr := json.Unmarshal(body, &m)
|
jerr := json.Unmarshal(body, &m)
|
||||||
|
|
Loading…
Reference in a new issue