Documentation
¶
Index ¶
- Variables
- type Config
- type Hook
- type HookList
- func (l *HookList) Clear()
- func (l *HookList) Debug() string
- func (l *HookList) Len() int
- func (l *HookList) PushBack(f func(*Request))
- func (l *HookList) PushBackHook(h Hook)
- func (l *HookList) PushFront(f func(*Request))
- func (l *HookList) PushFrontHook(h Hook)
- func (l *HookList) Remove(name string)
- func (l *HookList) RemoveHook(h Hook)
- func (l *HookList) Run(r *Request)
- func (l *HookList) Swap(name string, replace Hook)
- type Hooks
- type LogLevel
- type Logger
- type LoggerFunc
- type Operation
- type Option
- type Request
- type RetryConfig
- type Retryer
Constants ¶
This section is empty.
Variables ¶
var ( DefaultRetryConfig = RetryConfig{ InitialDelay: 1 * time.Second, Multiplier: 1, MaxDelay: 10 * time.Second, Jitter: 0, MaxRetries: 1, MaxElapsedTime: 5 * time.Second, } DefaultRetryer = retryer{} )
var ( // NoBody is an http.NoBody reader instructing the Go HTTP client to not include // a body in the HTTP request. NoBody = http.NoBody )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Endpoint is hostname or fully qualified URI of the service being called
Endpoint string
// Name of the external service being called
ServiceName string
// Set this to `true` to disable SSL when sending requests. Defaults
// to `false`
DisableSSL bool
// The HTTP client to use when sending requests
HTTPClient *http.Client
DisableFollowRedirects bool
LogLevel LogLevel
// The logger writer interface to write logging messages to. Defaults to
// standard out.
Logger Logger
// Unique ID to trace a request attempt
RequestID string
}
type HookList ¶
type HookList struct {
// contains filtered or unexported fields
}
func (*HookList) PushBackHook ¶
PushBackHook pushes hook h to the back of the hook list.
func (*HookList) PushFrontHook ¶
PushFrontHook pushes hook h to the front of the hook list
type Hooks ¶
type LogLevel ¶
type LogLevel uint
const ( // LogSilent state used to disable all logging. This is the default state LogSilent LogLevel = iota * 0x1000 // LogError state used to log when service requests fail // to build, send, validate, or unmarshal. LogError // LogDebug state can be used for debug output to inspect requests // made and responses received. LogDebug )
const ( // LogDebugWithHTTPBody state used to log HTTP request and response HTTP bodies // in addition to the headers and path. This should be used to see the body // content of requests and responses made. Will also enable LogDebug. LogDebugWithHTTPBody LogLevel = LogDebug | (1 << iota) // LogDebugWithRequestRetries state used to log when service requests will // be retried. This should be used to log when you want to log when service // requests are being retried. Will also enable LogDebug. LogDebugWithRequestRetries )
Debug Logging Sub Levels
type Logger ¶
type Logger interface {
Log(...any)
}
func NewDefaultLogger ¶
func NewDefaultLogger() Logger
NewDefaultLogger returns a Logger which will write log messages to stdout, and use same formatting runes as the stdlib log.Logger
type LoggerFunc ¶
type LoggerFunc func(...any)
A LoggerFunc is a convenience type to convert a function taking a variadic list of arguments and wrap it so the Logger interface can be used.
func (LoggerFunc) Log ¶
func (f LoggerFunc) Log(args ...any)
type Option ¶
type Option func(*Request)
An Option is a functional option that can augment or modify a request when using a WithContext API operation method.
func WithLogger ¶
WithLogger sets the logger func used with the request
func WithRequestHeader ¶
WithRequestHeader builds a request Option which will add an http header to the request.
func WithRequestID ¶
WithRequestID sets the request id in config
func WithServiceName ¶
WithServiceName sets the service name in config
type Request ¶
type Request struct {
Config Config
// request payload
Params any
// response body
Body any
Data any
Hooks Hooks
Error error
Retryer
RetryConfig RetryConfig
Operation *Operation
Request *http.Request
Response *http.Response
AttemptTime time.Time
// contains filtered or unexported fields
}
func New ¶
New returns a new Request pointer for the api operation and parameters.
Params is any value for the request payload.
Data is for the response payload
func (*Request) ApplyOptions ¶
ApplyOptions will apply each option to the request calling them in the order they were provided.
func (*Request) Build ¶
Build will build the request object to be sent. Build will also validate all the request's parameters.
If any Validate or Build errors occur, the build will stop and the error which occurred will be returned
func (*Request) Context ¶
Context will always return a non-nil context. If the Request does not have a context, context.Background will be returned.
func (*Request) WithContext ¶
func (*Request) WithRetryConfig ¶
func (r *Request) WithRetryConfig(cfg RetryConfig)
type RetryConfig ¶
type RetryConfig struct {
// InitialDelay before the first retry.
InitialDelay time.Duration
// Multiplier to apply to the delay interval between retries.
// Values >1 increase the delay interval exponentially, values <1 decrease it.
Multiplier float64
// MaximumDelay n at which to cap the delay interval between retries.
// As the delay interval increases, the highest interval will be capped
// at this value.
MaxDelay time.Duration
// Jitter is the amount of random jitter to apply to the delay interval
// between retries to prevent exact timing between retries.
// Valid values are between 0 and 1. A value of 0 disables Jitter.
Jitter float64
// CurrentDelay tracks the current delay interval between retries.
CurrentDelay time.Duration
// Number of retries attempted. Value should be incremented with each retry
RetryCount int
// Number of maximum allowed retries
MaxRetries int
// Maximum allowed time for retries
MaxElapsedTime time.Duration
// Additional API error codes that should be retried. IsErrorRetryable
// will consider these codes in addition to its built-in cases.
RetryErrorCodes []string
}