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