Documentation
¶
Overview ¶
Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0
Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0
Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0
Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0
Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0
Copyright 2022 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0
Index ¶
- Constants
- Variables
- func BuildTransport(cfg *config.Config, timeout time.Duration) http.RoundTripper
- func CheckEndpointHealthiness(ctx context.Context, endpointURL string, license string, userAgent string, ...) (bool, error)
- func CheckEndpointReachability(ctx context.Context, logger log.Entry, endpointURL string, license string, ...) (bool, error)
- func ContainsLocalhost(value string) bool
- func GetHttpClient(httpTimeout time.Duration, transport http.RoundTripper) *http.Client
- func IsLocalhost(value string) bool
- func IsResponseError(resp *http.Response) bool
- func IsResponseSuccess(resp *http.Response) bool
- func NewRequestDecoratorTransport(configurator config.Provider, transport http.RoundTripper) http.RoundTripper
- func ReplaceLocalhost(source, with string) string
- type Client
- type ErrorCause
- type Mock
- type RequestInterceptorMock
- type Response
- type ResponseMetadata
- type ResponseStack
- type RetryPolicy
- type StandardResponse
Constants ¶
const ( LicenseHeader = "X-License-Key" EntityKeyHeader = "X-NRI-Entity-Key" // populated with the agent-id for the backend deny mechanism AgentEntityIdHeader = "X-NRI-Agent-Entity-Id" TrialStatusHeader = "X-Trial-Status" TrialStarting = "starting" ClientTimeout = 30 * time.Second )
HTTP default values
const ( LOCALHOST = "localhost" LOCALHOST_IPV6 = "::1" LOCALHOST_PREFIX_IP = "127." )
Variables ¶
var ErrEmptyStack = errors.New("Empty stack")
var ErrUnexepectedResponseCode = errors.New("endpoint returned and unexpected response code")
var NullHttpClient = func(req *http.Request) (res *http.Response, err error) { _, _ = ioutil.ReadAll(req.Body) defer req.Body.Close() return }
NullHttpClient client discarding all the requests and returning empty objects.
Functions ¶
func BuildTransport ¶
BuildTransport creates an http.Transport. If there is a configured proxy, in the configuration and environment, it configures the transport to use the proxy, according to the following priorities (from larger to lower priority):
1. HTTPS_PROXY env var 2. NRIA_PROXY env var / proxy config option 3. HTTP_PROXY env var
If the configuration option ignore_system_proxy is set, it ignores the HTTPS_PROXY and HTTP_PROXY configuration If the configuration option proxy_validate_certificates is set, it will force the HTTPS proxy options to verify the certificates
func CheckEndpointHealthiness ¶ added in v1.67.3
func ContainsLocalhost ¶
ContainsLocalhost checks if the given value contains a reference a localhost hostname or ip
func GetHttpClient ¶
func IsLocalhost ¶
IsLocalhost checks if the given value is equal to a localhost hostname or ip
func IsResponseError ¶
IsResponseError is a non successful backend response.
func IsResponseSuccess ¶
IsResponseSuccess is a successful backend response
func NewRequestDecoratorTransport ¶ added in v1.67.3
func NewRequestDecoratorTransport(configurator config.Provider, transport http.RoundTripper) http.RoundTripper
NewRequestDecoratorTransport comes with ability to decorate http request objects.
func ReplaceLocalhost ¶
ReplaceLocalhost replaces the occurrence of a localhost address with the given hostname
Types ¶
type ErrorCause ¶
type ErrorCause string
ErrorCause is used to identify the type of the ingestError.
const ( // TrialInactive is returned when the trial had not been started. TrialInactive ErrorCause = "trial_inactive" // TrialExpired is returned when the trial had expired. TrialExpired ErrorCause = "trial_expired" // InvalidLicense is returned when the license key is invalid. InvalidLicense ErrorCause = "invalid_license" // ServiceError is the error returned by the identity service. ServiceError ErrorCause = "service_error" )
func IsResponseUnsuccessful ¶
func IsResponseUnsuccessful(resp *http.Response) (hasError bool, cause ErrorCause)
IsResponseUnsuccessful will return the cause of the error if it's the case.
type RequestInterceptorMock ¶ added in v1.67.3
type RequestInterceptorMock struct {
// contains filtered or unexported fields
}
func NewRequestInterceptorMock ¶ added in v1.67.3
func NewRequestInterceptorMock() *RequestInterceptorMock
type ResponseMetadata ¶
type ResponseMetadata struct {
Previous string `json:"previous,omitempty"`
Next string `json:"next,omitempty"`
Before string `json:"before,omitempty"`
After string `json:"after,omitempty"`
PerPage int `json:"per_page,omitempty"`
RateLimitLimit int `json:"rate_limit_limit,omitempty"`
RateLimitRemaining int `json:"rate_limit_remaining,omitempty"`
RateLimitReset int `json:"rate_limit_reset,omitempty"`
Stats map[string]interface{} `json:"stats,omitempty"`
}
type ResponseStack ¶
type ResponseStack []*Response
func (ResponseStack) Empty ¶
func (s ResponseStack) Empty() bool
func (ResponseStack) Peek ¶
func (s ResponseStack) Peek() *Response
func (*ResponseStack) Pop ¶
func (s *ResponseStack) Pop() *Response
func (*ResponseStack) Put ¶
func (s *ResponseStack) Put(v *Response)
type RetryPolicy ¶
RetryPolicy defines the retry behaviour.
type StandardResponse ¶
type StandardResponse struct {
Payload interface{} `json:"payload"`
Metadata *ResponseMetadata `json:"metadata,omitempty"`
}