Documentation ¶
Index ¶
- Constants
- Variables
- func RetryPolicy(ctx context.Context, resp *http.Response, err error) (bool, error)
- type ClassicV2Authorizer
- type Client
- func (c *Client) Delete(url string, queryParams interface{}, respBody interface{}) (*http.Response, error)
- func (c *Client) DeleteWithContext(ctx context.Context, url string, queryParams interface{}, respBody interface{}) (*http.Response, error)
- func (c *Client) Do(req *Request) (*http.Response, error)
- func (c *Client) Get(url string, queryParams interface{}, respBody interface{}) (*http.Response, error)
- func (c *Client) GetWithContext(ctx context.Context, url string, queryParams interface{}, respBody interface{}) (*http.Response, error)
- func (c *Client) NerdGraphQuery(query string, vars map[string]interface{}, respBody interface{}) error
- func (c *Client) NerdGraphQueryWithContext(ctx context.Context, query string, vars map[string]interface{}, ...) error
- func (c *Client) NewNerdGraphRequest(query string, vars map[string]interface{}, respBody interface{}) (*Request, error)
- func (c *Client) NewRequest(method string, url string, params interface{}, reqBody interface{}, ...) (*Request, error)
- func (c *Client) Post(url string, queryParams interface{}, reqBody interface{}, respBody interface{}) (*http.Response, error)
- func (c *Client) PostWithContext(ctx context.Context, url string, queryParams interface{}, reqBody interface{}, ...) (*http.Response, error)
- func (c *Client) Put(url string, queryParams interface{}, reqBody interface{}, respBody interface{}) (*http.Response, error)
- func (c *Client) PutWithContext(ctx context.Context, url string, queryParams interface{}, reqBody interface{}, ...) (*http.Response, error)
- func (c *Client) SetAuthStrategy(da RequestAuthorizer)
- func (c *Client) SetErrorValue(v ErrorResponse) *Client
- func (c *Client) SetRequestCompressor(compressor RequestCompressor)
- type DefaultErrorResponse
- func (e *DefaultErrorResponse) Error() string
- func (e *DefaultErrorResponse) IsDeprecated() bool
- func (e *DefaultErrorResponse) IsNotFound() bool
- func (e *DefaultErrorResponse) IsPaymentRequired(resp *http.Response) bool
- func (e *DefaultErrorResponse) IsRetryableError() bool
- func (e *DefaultErrorResponse) IsUnauthorized(resp *http.Response) bool
- func (e *DefaultErrorResponse) New() ErrorResponse
- type ErrorDetail
- type ErrorResponse
- type GraphQLError
- type GraphQLErrorResponse
- func (r *GraphQLErrorResponse) Error() string
- func (r *GraphQLErrorResponse) IsDeprecated() bool
- func (r *GraphQLErrorResponse) IsNotFound() bool
- func (r *GraphQLErrorResponse) IsPaymentRequired(resp *http.Response) bool
- func (r *GraphQLErrorResponse) IsRetryableError() bool
- func (r *GraphQLErrorResponse) IsUnauthorized(resp *http.Response) bool
- func (r *GraphQLErrorResponse) New() ErrorResponse
- type GzipCompressor
- type InsightsInsertKeyAuthorizer
- type LicenseKeyAuthorizer
- type LinkHeaderPager
- type LogsInsertKeyAuthorizer
- type NerdGraphAuthorizer
- type NoneCompressor
- type Pager
- type Paging
- type PersonalAPIKeyCapableV2Authorizer
- type Request
- func (r *Request) DelHeader(key string)
- func (r *Request) GetHeader(key string) string
- func (r *Request) SetAuthStrategy(ra RequestAuthorizer)
- func (r *Request) SetErrorValue(e ErrorResponse)
- func (r *Request) SetHeader(key string, value string)
- func (r *Request) SetServiceName(serviceName string)
- func (r *Request) WithContext(ctx context.Context)
- type RequestAuthorizer
- type RequestCompressor
Constants ¶
const (
// CompressorMinimumSize is the required size in bytes that a body exceeds before it is compressed
CompressorMinimumSize = 150
)
Variables ¶
var ( // ErrNotFound is returned when the resource was not found in New Relic. ErrNotFound = errors.New("newrelic: Resource not found") // ErrClassTooManyRequests is returned in json messages when client is sending more RPM than the service limit. // (RPM = Requests Per Minute) ErrClassTooManyRequests = errors.New("TOO_MANY_REQUESTS") )
Functions ¶
Types ¶
type ClassicV2Authorizer ¶
type ClassicV2Authorizer struct{}
ClassicV2Authorizer authorizes V2 endpoints that cannot use a personal API key.
func (*ClassicV2Authorizer) AuthorizeRequest ¶
func (a *ClassicV2Authorizer) AuthorizeRequest(r *Request, c *config.Config)
AuthorizeRequest is responsible for setting up auth for a request.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a client for communicating with the New Relic APIs.
func NewTestAPIClient ¶
NewTestAPIClient returns a test Client instance that is configured to communicate with a mock server.
func (*Client) Delete ¶
func (c *Client) 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 (*Client) DeleteWithContext ¶
func (c *Client) DeleteWithContext( ctx context.Context, url string, queryParams interface{}, respBody interface{}, ) (*http.Response, error)
DeleteWithContext 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 (*Client) Get ¶
func (c *Client) 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 (*Client) GetWithContext ¶
func (c *Client) GetWithContext( ctx context.Context, url string, queryParams interface{}, respBody interface{}, ) (*http.Response, error)
GetWithContext 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 (*Client) NerdGraphQuery ¶
func (c *Client) NerdGraphQuery(query string, vars map[string]interface{}, respBody interface{}) error
NerdGraphQuery runs a Nerdgraph query.
func (*Client) NerdGraphQueryWithContext ¶
func (c *Client) NerdGraphQueryWithContext(ctx context.Context, query string, vars map[string]interface{}, respBody interface{}) error
NerdGraphQueryWithContext runs a Nerdgraph query.
func (*Client) NewNerdGraphRequest ¶
func (c *Client) NewNerdGraphRequest(query string, vars map[string]interface{}, respBody interface{}) (*Request, error)
NewNerdGraphRequest runs a Nerdgraph request object.
func (*Client) NewRequest ¶
func (c *Client) NewRequest(method string, url string, params interface{}, reqBody interface{}, value interface{}) (*Request, error)
NewRequest creates a new Request struct.
func (*Client) Post ¶
func (c *Client) 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 (*Client) PostWithContext ¶
func (c *Client) PostWithContext( ctx context.Context, url string, queryParams interface{}, reqBody interface{}, respBody interface{}, ) (*http.Response, error)
PostWithContext 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 (*Client) Put ¶
func (c *Client) 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 (*Client) PutWithContext ¶
func (c *Client) PutWithContext( ctx context.Context, url string, queryParams interface{}, reqBody interface{}, respBody interface{}, ) (*http.Response, error)
PutWithContext 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 (*Client) SetAuthStrategy ¶
func (c *Client) SetAuthStrategy(da RequestAuthorizer)
SetAuthStrategy is used to set the default auth strategy for this client which can be overridden per request
func (*Client) SetErrorValue ¶
func (c *Client) SetErrorValue(v ErrorResponse) *Client
SetErrorValue is used to unmarshal error body responses in JSON format.
func (*Client) SetRequestCompressor ¶
func (c *Client) SetRequestCompressor(compressor RequestCompressor)
SetRequestCompressor is used to enable compression on the request using the RequestCompressor specified
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
func (*DefaultErrorResponse) IsDeprecated ¶
func (e *DefaultErrorResponse) IsDeprecated() bool
func (*DefaultErrorResponse) IsNotFound ¶
func (e *DefaultErrorResponse) IsNotFound() bool
func (*DefaultErrorResponse) IsPaymentRequired ¶
func (e *DefaultErrorResponse) IsPaymentRequired(resp *http.Response) bool
func (*DefaultErrorResponse) IsRetryableError ¶
func (e *DefaultErrorResponse) IsRetryableError() bool
func (*DefaultErrorResponse) IsUnauthorized ¶
func (e *DefaultErrorResponse) IsUnauthorized(resp *http.Response) bool
IsUnauthorized checks a response for a 401 Unauthorize HTTP status code.
func (*DefaultErrorResponse) New ¶
func (e *DefaultErrorResponse) New() ErrorResponse
New creates a new instance of the DefaultErrorResponse struct.
type ErrorDetail ¶
ErrorDetail represents a New Relic response error detail.
type ErrorResponse ¶
type ErrorResponse interface { IsNotFound() bool IsRetryableError() bool IsPaymentRequired(resp *http.Response) bool IsDeprecated() bool Error() string New() ErrorResponse }
ErrorResponse provides an interface for obtaining a single error message from an error response object.
type GraphQLError ¶
type GraphQLError struct { Message string `json:"message,omitempty"` Path []string `json:"path,omitempty"` Extensions struct { ErrorClass string `json:"errorClass,omitempty"` ErrorCode string `json:"error_code,omitempty"` Code string `json:"code,omitempty"` } `json:"extensions,omitempty"` }
GraphQLError represents a single error.
type GraphQLErrorResponse ¶
type GraphQLErrorResponse struct {
Errors []GraphQLError `json:"errors"`
}
GraphQLErrorResponse represents a default error response body.
func (*GraphQLErrorResponse) Error ¶
func (r *GraphQLErrorResponse) Error() string
func (*GraphQLErrorResponse) IsDeprecated ¶
func (r *GraphQLErrorResponse) IsDeprecated() bool
IsDeprecated parses error messages for warnings that a field being used is deprecated. We want to bubble that up, but not stop returning data
Example deprecation message:
This field is deprecated! Please use `relatedEntities` instead.
func (*GraphQLErrorResponse) IsNotFound ¶
func (r *GraphQLErrorResponse) IsNotFound() bool
IsNotFound determines if the error is due to a missing resource.
func (*GraphQLErrorResponse) IsPaymentRequired ¶
func (r *GraphQLErrorResponse) IsPaymentRequired(resp *http.Response) bool
func (*GraphQLErrorResponse) IsRetryableError ¶
func (r *GraphQLErrorResponse) IsRetryableError() bool
IsRetryableError determines if the error is due to a server timeout, or another error that we might want to retry.
func (*GraphQLErrorResponse) IsUnauthorized ¶
func (r *GraphQLErrorResponse) IsUnauthorized(resp *http.Response) bool
IsUnauthorized checks a NerdGraph response for a 401 Unauthorize HTTP status code, then falls back to check the nested extensions error_code field for `BAD_API_KEY`.
func (*GraphQLErrorResponse) New ¶
func (r *GraphQLErrorResponse) New() ErrorResponse
New creates a new instance of GraphQLErrorRepsonse.
type InsightsInsertKeyAuthorizer ¶
type InsightsInsertKeyAuthorizer struct{}
InsightsInsertKeyAuthorizer authorizes sending custom events to New Relic.
func (*InsightsInsertKeyAuthorizer) AuthorizeRequest ¶
func (a *InsightsInsertKeyAuthorizer) AuthorizeRequest(r *Request, c *config.Config)
type LicenseKeyAuthorizer ¶
type LicenseKeyAuthorizer struct{}
func (*LicenseKeyAuthorizer) AuthorizeRequest ¶
func (a *LicenseKeyAuthorizer) AuthorizeRequest(r *Request, c *config.Config)
type LinkHeaderPager ¶
type LinkHeaderPager struct{}
LinkHeaderPager represents a pagination implementation that adheres to RFC 5988.
type LogsInsertKeyAuthorizer ¶
type LogsInsertKeyAuthorizer struct{}
func (*LogsInsertKeyAuthorizer) AuthorizeRequest ¶
func (a *LogsInsertKeyAuthorizer) AuthorizeRequest(r *Request, c *config.Config)
type NerdGraphAuthorizer ¶
type NerdGraphAuthorizer struct{}
NerdGraphAuthorizer authorizes calls to NerdGraph.
func (*NerdGraphAuthorizer) AuthorizeRequest ¶
func (a *NerdGraphAuthorizer) AuthorizeRequest(r *Request, c *config.Config)
AuthorizeRequest is responsible for setting up auth for a request.
type NoneCompressor ¶
type NoneCompressor struct{}
NoneCompressor does not compress the request at all.
type Paging ¶
type Paging struct {
Next string
}
Paging represents the pagination context returned from the Pager implementation.
type PersonalAPIKeyCapableV2Authorizer ¶
type PersonalAPIKeyCapableV2Authorizer struct{}
PersonalAPIKeyCapableV2Authorizer authorizes V2 endpoints that can use a personal API key.
func (*PersonalAPIKeyCapableV2Authorizer) AuthorizeRequest ¶
func (a *PersonalAPIKeyCapableV2Authorizer) AuthorizeRequest(r *Request, c *config.Config)
AuthorizeRequest is responsible for setting up auth for a request.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request represents a configurable HTTP request.
func (*Request) SetAuthStrategy ¶
func (r *Request) SetAuthStrategy(ra RequestAuthorizer)
SetAuthStrategy sets the authentication strategy for the request.
func (*Request) SetErrorValue ¶
func (r *Request) SetErrorValue(e ErrorResponse)
SetErrorValue sets the error object for the request.
func (*Request) SetServiceName ¶
SetServiceName sets the service name for the request.
func (*Request) WithContext ¶
WithContext sets the context of the underlying request.
type RequestAuthorizer ¶
RequestAuthorizer is an interface that allows customizatino of how a request is authorized.