forked from mtusi2026/mtusi2026lab4
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29970e248a | ||
|
|
cb94ca6789 | ||
|
|
6a29caf911 |
@@ -480,7 +480,7 @@ func (c *apiClient) upload(
|
||||
if err != nil {
|
||||
return attachment{}, err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
defer func() { _ = response.Body.Close() }()
|
||||
if response.StatusCode != http.StatusCreated {
|
||||
message, _ := io.ReadAll(io.LimitReader(response.Body, 4096))
|
||||
return attachment{}, fmt.Errorf("upload status %d: %s", response.StatusCode, message)
|
||||
@@ -532,7 +532,7 @@ func (c *apiClient) jsonRequest(
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
defer func() { _ = response.Body.Close() }()
|
||||
if response.StatusCode < 200 || response.StatusCode >= 300 {
|
||||
message, _ := io.ReadAll(io.LimitReader(response.Body, 4096))
|
||||
return fmt.Errorf("%s %s status %d: %s", method, path, response.StatusCode, message)
|
||||
@@ -579,9 +579,9 @@ func prometheusValue(ctx context.Context, baseURL, query string) (int64, error)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
defer func() { _ = response.Body.Close() }()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return 0, fmt.Errorf("Prometheus status %d", response.StatusCode)
|
||||
return 0, fmt.Errorf("prometheus status %d", response.StatusCode)
|
||||
}
|
||||
var payload struct {
|
||||
Status string `json:"status"`
|
||||
@@ -595,7 +595,7 @@ func prometheusValue(ctx context.Context, baseURL, query string) (int64, error)
|
||||
return 0, err
|
||||
}
|
||||
if payload.Status != "success" || len(payload.Data.Result) != 1 || len(payload.Data.Result[0].Value) != 2 {
|
||||
return 0, fmt.Errorf("Prometheus query returned no scalar value")
|
||||
return 0, errors.New("prometheus query returned no scalar value")
|
||||
}
|
||||
var raw string
|
||||
if err := json.Unmarshal(payload.Data.Result[0].Value[1], &raw); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user