fix: close Body correctly
This commit is contained in:
parent
02580cce20
commit
254effa8e5
2 changed files with 6 additions and 3 deletions
|
|
@ -47,6 +47,9 @@ func sendRequest(ctx context.Context, url string, body interface{}, headers http
|
||||||
|
|
||||||
status := resp.StatusCode
|
status := resp.StatusCode
|
||||||
if status < 200 || status >= 300 {
|
if status < 200 || status >= 300 {
|
||||||
|
defer func() {
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
}()
|
||||||
return nil, fmt.Errorf("request failed with status %d", status)
|
return nil, fmt.Errorf("request failed with status %d", status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,11 +120,11 @@ func (h *UmamiFeeder) reportEventToUmami(ctx context.Context, event *UmamiPayloa
|
||||||
|
|
||||||
h.debug("sending tracking request %s with body %v %v", event.body.Payload.Url, event.body, event.headers)
|
h.debug("sending tracking request %s with body %v %v", event.body.Payload.Url, event.body, event.headers)
|
||||||
resp, err := sendRequest(ctx, h.umamiHost+"/api/send", event.body, event.headers)
|
resp, err := sendRequest(ctx, h.umamiHost+"/api/send", event.body, event.headers)
|
||||||
defer func() {
|
|
||||||
_ = resp.Body.Close()
|
|
||||||
}()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.error("failed to send tracking: " + err.Error())
|
h.error("failed to send tracking: " + err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue