Exemplo n.º 1
0
// get returns an array of byte which contains the response body
func (s *Sensu) getMap(endpoint string) (map[string]interface{}, error) {
	body, _, err := s.get(fmt.Sprintf("%s/%s", s.URL, endpoint))
	if err != nil {
		return nil, err
	}
	return helpers.GetMapFromBytes(body)
}
Exemplo n.º 2
0
// post performs a POST HTTP request to a provided endpoint
func (api *API) post(endpoint string) (map[string]interface{}, error) {
	url := fmt.Sprintf("%s/%s", api.URL, endpoint)

	req, err := http.NewRequest("POST", url, nil)
	if err != nil {
		return nil, err
	}

	body, _, err := api.doRequest(req)
	if err != nil {
		return nil, err
	}

	return helpers.GetMapFromBytes(body)
}
Exemplo n.º 3
0
// Post to endpoint
func (s *Sensu) post(endpoint string) (map[string]interface{}, error) {
	url := fmt.Sprintf("%s/%s", s.URL, endpoint)

	req, err := http.NewRequest("POST", url, nil)
	if err != nil {
		return nil, fmt.Errorf("Parsing error: %q returned: %v", url, err)
	}

	body, _, err := s.doHTTP(req)
	if err != nil {
		return nil, fmt.Errorf("API call to %q returned: %v", url, err)
	}

	return helpers.GetMapFromBytes(body)
}
Exemplo n.º 4
0
// postPayload to endpoint
func (s *Sensu) postPayload(endpoint string, payload string) (map[string]interface{}, error) {
	url := fmt.Sprintf("%s/%s", s.URL, endpoint)

	req, err := http.NewRequest("POST", url, strings.NewReader(fmt.Sprintf("%s\n\n", payload)))
	if err != nil {
		return nil, fmt.Errorf("Parsing error: %q returned: %v", url, err)
	}

	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Content-Length", fmt.Sprintf("%d", len(payload)))

	body, _, err := s.doHTTP(req)
	if err != nil {
		return nil, fmt.Errorf("API call to %q returned: %v", url, err)
	}

	return helpers.GetMapFromBytes(body)
}