Ejemplo n.º 1
0
func addDrain(channelId, drainUrl string) (*DrainResponse, error) {
	var payload struct {
		Url string `json:"url"`
	}
	payload.Url = drainUrl

	req := goreq.Request{
		Method:      "POST",
		Uri:         fmt.Sprintf("%s/v2/channels/%s/drains", config.Endpoint, channelId),
		Body:        payload,
		ContentType: "application/json",
	}.WithHeader("Authorization", fmt.Sprintf("Basic %s", config.AuthKey))

	response, err := req.Do()
	if err != nil {
		return nil, err
	}
	defer response.Body.Close()

	if response.StatusCode != 201 {
		return nil, fmt.Errorf("Unsuccessful response (%v) from logplex", response.Status)
	}

	var drainResponse DrainResponse
	err = response.Body.FromJsonTo(&drainResponse)
	if err != nil {
		return nil, err
	}

	return &drainResponse, err
}
Ejemplo n.º 2
0
func createChannel(payload *ChannelRequest) (*ChannelResponse, error) {
	// TODO: possibly ignore request certificates
	// https://github.com/heroku/heroku-cli/commit/75403de1a0d581e1eb9acfffe9ab0443e3f36a38
	req := goreq.Request{
		Method:      "POST",
		Uri:         fmt.Sprintf("%s/channels", config.Endpoint),
		Body:        payload,
		ContentType: "application/json",
	}.WithHeader("Authorization", fmt.Sprintf("Basic %s", config.AuthKey))

	response, err := req.Do()
	if err != nil {
		return nil, err
	}
	defer response.Body.Close()

	if response.StatusCode != 201 {
		return nil, fmt.Errorf("Unsuccessful response (%v) from logplex", response.Status)
	}

	var channelResponse ChannelResponse
	err = response.Body.FromJsonTo(&channelResponse)
	if err != nil {
		return nil, err
	}

	return &channelResponse, err
}
Ejemplo n.º 3
0
func removeDrain(channelId, drainId string) error {
	req := goreq.Request{
		Method: "DELETE",
		Uri:    fmt.Sprintf("%s/v2/channels/%s/drains/%s", config.Endpoint, channelId, drainId),
	}.WithHeader("Authorization", fmt.Sprintf("Basic %s", config.AuthKey))

	response, err := req.Do()
	if err != nil {
		return err
	}
	defer response.Body.Close()

	if response.StatusCode != 200 {
		return fmt.Errorf("Unsuccessful response (%v) from logplex", response.Status)
	}
	return nil
}