http

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when the resource was not found in New Relic.
	ErrNotFound = errors.New("newrelic: Resource not found")
)

Functions

func RetryPolicy

func RetryPolicy(ctx context.Context, resp *http.Response, err error) (bool, error)

RetryPolicy provides a callback for retryablehttp's CheckRetry, which will retry on connection errors and server errors.

Types

type DefaultErrorResponse

type DefaultErrorResponse struct {
	ErrorDetail ErrorDetail `json:"error"`
}

DefaultErrorResponse represents the default error response from New Relic.

func (*DefaultErrorResponse) Error

func (e *DefaultErrorResponse) Error() string

type ErrorDetail

type ErrorDetail struct {
	Title    string   `json:"title"`
	Messages []string `json:"messages"`
}

ErrorDetail represents a New Relic response error detail.

type ErrorResponse

type ErrorResponse interface {
	Error() string
}

ErrorResponse provides an interface for obtaining a single error message from an error response object.

type GraphQLClient added in v0.4.0

type GraphQLClient struct {
	Client *NewRelicClient
	// contains filtered or unexported fields
}

GraphQLClient represents a graphQL HTTP client.

func NewGraphQLClient added in v0.4.0

func NewGraphQLClient(cfg config.Config) *GraphQLClient

NewGraphQLClient returns a new instance of GraphQLClient.

func (*GraphQLClient) Query added in v0.4.0

func (g *GraphQLClient) Query(query string, vars map[string]interface{}, respBody interface{}) error

Query runs a graphQL query.

type LinkHeaderPager

type LinkHeaderPager struct{}

LinkHeaderPager represents a pagination implementation that adheres to RFC 5988.

func (*LinkHeaderPager) Parse

func (l *LinkHeaderPager) Parse(resp *http.Response) Paging

Parse is used to parse a pagination context from an HTTP response.

type NewRelicClient

type NewRelicClient struct {
	Client *retryablehttp.Client
	Config config.Config
	// contains filtered or unexported fields
}

NewRelicClient represents a client for communicating with the New Relic APIs.

func NewClient

func NewClient(cfg config.Config) NewRelicClient

NewClient is used to create a new instance of NewRelicClient.

func NewTestAPIClient

func NewTestAPIClient(handler http.Handler) NewRelicClient

NewTestAPIClient returns a test NewRelicClient instance that is configured to communicate with a mock server.

func (*NewRelicClient) Delete

func (c *NewRelicClient) Delete(url string,
	queryParams interface{},
	respBody interface{},
) (*http.Response, error)

Delete represents an HTTP DELETE request to a New Relic API. The queryParams argument can be used to add query string parameters to the requested URL. The respBody argument will be unmarshaled from JSON in the response body to the type provided. If respBody is not nil and the response body cannot be unmarshaled to the type provided, an error will be returned.

func (*NewRelicClient) Get

func (c *NewRelicClient) Get(
	url string,
	queryParams interface{},
	respBody interface{},
) (*http.Response, error)

Get represents an HTTP GET request to a New Relic API. The queryParams argument can be used to add query string parameters to the requested URL. The respBody argument will be unmarshaled from JSON in the response body to the type provided. If respBody is not nil and the response body cannot be unmarshaled to the type provided, an error will be returned.

func (*NewRelicClient) Post

func (c *NewRelicClient) Post(
	url string,
	queryParams interface{},
	reqBody interface{},
	respBody interface{},
) (*http.Response, error)

Post represents an HTTP POST request to a New Relic API. The queryParams argument can be used to add query string parameters to the requested URL. The reqBody argument will be marshaled to JSON from the type provided and included in the request body. The respBody argument will be unmarshaled from JSON in the response body to the type provided. If respBody is not nil and the response body cannot be unmarshaled to the type provided, an error will be returned.

func (*NewRelicClient) Put

func (c *NewRelicClient) Put(
	url string,
	queryParams interface{},
	reqBody interface{},
	respBody interface{},
) (*http.Response, error)

Put represents an HTTP PUT request to a New Relic API. The queryParams argument can be used to add query string parameters to the requested URL. The reqBody argument will be marshaled to JSON from the type provided and included in the request body. The respBody argument will be unmarshaled from JSON in the response body to the type provided. If respBody is not nil and the response body cannot be unmarshaled to the type provided, an error will be returned.

func (*NewRelicClient) SetErrorValue

func (c *NewRelicClient) SetErrorValue(v ErrorResponse) *NewRelicClient

SetErrorValue is used to unmarshal error body responses in JSON format.

type Pager

type Pager interface {
	Parse(res *http.Response) Paging
}

Pager represents a pagination implementation.

type Paging

type Paging struct {
	Next string
}

Paging represents the pagination context returned from the Pager implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL