| 44 | } |
| 45 | |
| 46 | func (c *client) Awaken(api userconfig.Resource) error { |
| 47 | payload, err := json.Marshal(api) |
| 48 | if err != nil { |
| 49 | return err |
| 50 | } |
| 51 | |
| 52 | response, err := c.httpClient.Post( |
| 53 | urls.Join(c.endpoint, "/awaken"), "application/json", bytes.NewBuffer(payload), |
| 54 | ) |
| 55 | if err != nil { |
| 56 | return err |
| 57 | } |
| 58 | defer func() { _ = response.Body.Close() }() |
| 59 | |
| 60 | if response.StatusCode != http.StatusOK { |
| 61 | bodyBytes, _ := ioutil.ReadAll(response.Body) |
| 62 | errMsg := fmt.Sprintf("failed to awake api (status code %d)", response.StatusCode) |
| 63 | if bodyBytes != nil { |
| 64 | errMsg = errMsg + fmt.Sprintf(": %s", string(bodyBytes)) |
| 65 | } |
| 66 | |
| 67 | return fmt.Errorf(errMsg) |
| 68 | } |
| 69 | |
| 70 | return nil |
| 71 | } |