func (cli *OpsGenieAlertClient) AssignOwner(req alerts.AssignOwnerAlertRequest) (*alerts.AssignOwnerAlertResponse, error) { req.ApiKey = cli.apiKey // validate the mandatory parameters: apiKey, alertId/alias, owner if req.ApiKey == "" { return nil, errors.New("ApiKey is a mandatory field and can not be empty.") } if req.Owner == "" { return nil, errors.New("Owner is a mandatory field and can not be empty") } if req.AlertId == "" && req.Alias == "" { return nil, errors.New("At least either Alert Id or Alias should be set in the request.") } if req.AlertId != "" && req.Alias != "" { return nil, errors.New("Either Alert Id or Alias should be set in the request not both.") } var resp *goreq.Response var err error for i := 0; i < cli.retries; i++ { resp, err = cli.buildRequest("POST", ASSIGN_OWNERSHIP_ALERT_URL, req).Do() if err == nil { break } time.Sleep(TIME_SLEEP_BETWEEN_REQUESTS) } if err != nil { return nil, errors.New("Can not assign the owner, unable to send the request") } // check the returning HTTP status code httpStatusCode := resp.StatusCode if httpStatusCode >= 400 && httpStatusCode < 500 { return nil, errors.New(fmt.Sprintf("Client error %d returned", httpStatusCode)) } if httpStatusCode >= 500 { return nil, errors.New(fmt.Sprintf("Server error %d returned", httpStatusCode)) } var assignOwnerAlertResp alerts.AssignOwnerAlertResponse // check if the response can be unmarshalled if err = resp.Body.FromJsonTo(&assignOwnerAlertResp); err != nil { return nil, errors.New("Server response can not be parsed.") } return &assignOwnerAlertResp, nil }