Documentation ¶
Index ¶
- Constants
- Variables
- func BSONTime(t time.Time) time.Time
- func BoolPtrCopy(in *bool) *bool
- func ChecksumFile(hash hash.Hash, path string) (string, error)
- func ConsistentFilepath(parts ...string) string
- func ContainsOrderedSubset[T comparable](superset, subset []T) bool
- func ContainsOrderedSubsetWithComparator[T any](superset, subset []T, compare func(T, T) bool) bool
- func ContextWithAttributes(ctx context.Context, attributes []attribute.KeyValue) context.Context
- func DefaultHttpClient(rt http.RoundTripper) *http.Client
- func DefaultTransport() *http.Transport
- func FalsePtr() *bool
- func FileExists(path string) bool
- func FilterSlice[T any](slice []T, filterFunction func(T) bool) []T
- func FromBoolPtr(in *bool) bool
- func FromBoolTPtr(in *bool) bool
- func FromBytePtr(in *byte) byte
- func FromFloat32Ptr(in *float32) float32
- func FromFloat64Ptr(in *float64) float64
- func FromInt32Ptr(in *int32) int32
- func FromInt64Ptr(in *int64) int64
- func FromIntPtr(in *int) int
- func FromNanoseconds(duration time.Duration) int64
- func FromPythonTime(pyTime float64) time.Time
- func FromStringPtr(in *string) string
- func FromStringPtrSlice(in []*string) []string
- func FromTimeDurationPtr(in *time.Duration) time.Duration
- func FromTimePtr(in *time.Time) time.Time
- func FromUintPtr(in *uint) uint
- func GetCustomHTTPRetryableClient(retry HTTPRetryFunction, delay HTTPDelayFunction) *http.Client
- func GetCustomHTTPRetryableClientWithTransport(rt http.RoundTripper, retry HTTPRetryFunction, delay HTTPDelayFunction) *http.Client
- func GetDefaultHTTPRetryableClient() *http.Client
- func GetHTTPClient() *http.Client
- func GetHTTPRetryableClient(conf HTTPRetryConfiguration) *http.Client
- func GetOAuth2HTTPClient(oauthToken string) *http.Client
- func GetOauth2CustomHTTPRetryableClient(token string, retry HTTPRetryFunction, delay HTTPDelayFunction) *http.Client
- func GetOauth2DefaultHTTPRetryableClient(oauthToken string) *http.Client
- func GetOauth2HTTPRetryableClient(oauthToken string, conf HTTPRetryConfiguration) *http.Client
- func GetPublicIP() (string, error)
- func GetSetDifference(a, b []string) []string
- func GetUTCDay(date time.Time) time.Time
- func GetUTCHour(date time.Time) time.Time
- func IndexOf(a []string, toFind string) int
- func IsContextError(err error) bool
- func IsTemporaryError(err error) bool
- func IsZeroTime(t time.Time) bool
- func JitterInterval(interval time.Duration) time.Duration
- func MD5SumFile(path string) (string, error)
- func MakeRandomString(size int) string
- func MakeSliceBatches[T any](elems []T, maxElemsPerBatch int) [][]T
- func MatchesError[T error](err error) bool
- func NewAttributeSpanProcessor() trace.SpanProcessor
- func NewPaginatedReadCloser(ctx context.Context, client *http.Client, resp *http.Response, ...) *paginatedReadCloser
- func NewRequestReader(req *http.Request) io.ReadCloser
- func NewRequestReaderWithSize(req *http.Request, size int64) io.ReadCloser
- func NewResponseReader(req *http.Response) io.ReadCloser
- func NewResponseReaderWithSize(req *http.Response, size int64) io.ReadCloser
- func NopWriteCloser(w io.Writer) io.WriteCloser
- func PrintJSON(data interface{}) error
- func PutHTTPClient(c *http.Client)
- func RandomString() string
- func ReadJSON(r io.ReadCloser, target interface{}) error
- func ReadJSONFile(path string, target interface{}) error
- func ReadYAML(r io.ReadCloser, target interface{}) error
- func ReadYAMLFile(path string, target interface{}) error
- func ReadYAMLFileStrict(path string, target interface{}) error
- func ReadYAMLStrict(r io.ReadCloser, target interface{}) error
- func Retry(ctx context.Context, op RetryableFunc, opts RetryOptions) error
- func RetryRequest(ctx context.Context, r *http.Request, opts RetryRequestOptions) (*http.Response, error)
- func RoundPartOfDay(n int) time.Time
- func RoundPartOfHour(n int) time.Time
- func RoundPartOfMinute(n int) time.Time
- func SHA1SumFile(path string) (string, error)
- func SetupOauth2CustomHTTPRetryableClient(token string, retry HTTPRetryFunction, delay HTTPDelayFunction, ...) *http.Client
- func SetupOauth2HTTPClient(token string, client *http.Client) *http.Client
- func SplitCommas(originals []string) []string
- func StringMatchesAnyRegex(item string, regexps []string) bool
- func StringSliceContains(slice []string, item string) bool
- func StringSliceContainsOrderedPrefixSubset(superset, subset []string) bool
- func StringSliceIntersection(a, b []string) []string
- func StringSliceSymmetricDifference(a, b []string) ([]string, []string)
- func ToBoolPtr(in bool) *bool
- func ToBytePtr(in byte) *byte
- func ToFloat32Ptr(in float32) *float32
- func ToFloat64Ptr(in float64) *float64
- func ToInt32Ptr(in int32) *int32
- func ToInt64Ptr(in int64) *int64
- func ToIntPtr(in int) *int
- func ToNanoseconds(duration time.Duration) time.Duration
- func ToPythonTime(t time.Time) float64
- func ToStringPtr(in string) *string
- func ToStringPtrSlice(in []string) []*string
- func ToTimeDurationPtr(in time.Duration) *time.Duration
- func ToTimePtr(in time.Time) *time.Time
- func ToUintPtr(in uint) *uint
- func TruePtr() *bool
- func UniqueStrings(slice []string) []string
- func UnixMilli(t time.Time) int64
- func WriteFile(path string, data string) error
- func WriteJSONFile(fn string, data interface{}) error
- func WriteRawFile(path string, data []byte) error
- func WriteYAMLFile(fn string, data interface{}) error
- type AlwaysMatch
- type FileAlwaysMatch
- type FileListBuilder
- type FileMatcher
- type HTTPDelayFunction
- type HTTPRetryConfiguration
- type HTTPRetryFunction
- type Hash
- type MockHandler
- type NeverMatch
- type RetryOptions
- type RetryRequestOptions
- type RetryableFunc
- type SafeBuffer
- type TemporaryError
Constants ¶
const Day = 24 * time.Hour
Day is the duration of one whole typical day (aside from unusual cases like Daylight Savings Time when there's not 24 hours in a single date).
const (
WalkThroughError = "walking through file tree"
)
Variables ¶
var MaxTime time.Time = time.Unix(1<<63-62135596801, 999999999)
MaxTime represents the latest useful golang date (219248499-12-06 15:30:07.999999999 +0000 UTC)
var Weekdays = []time.Weekday{time.Sunday, time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday, time.Saturday}
Weekdays contains all valid days of the week.
var ZeroTime time.Time = time.Unix(0, 0)
ZeroTime represents 0 in epoch time
Functions ¶
func BSONTime ¶
BSONTime converts a timestamp to how it would be represented in BSON such that, if the resulting timestamp is roundtripped to BSON and back, the timestamps would be identical.
func BoolPtrCopy ¶
BoolPtrCopy creates a new pointer with the same value as in.
func ChecksumFile ¶
ChecksumFile returns the checksum of a file given by path using the given hash.
func ConsistentFilepath ¶
ConsistentFilepath returns a filepath that always uses forward slashes ('/') rather than platform-dependent file path separators.
func ContainsOrderedSubset ¶
func ContainsOrderedSubset[T comparable](superset, subset []T) bool
ContainsOrderedSubset returns whether a slice contains an ordered subset using the equality operator.
func ContainsOrderedSubsetWithComparator ¶
ContainsOrderedSubsetWithComparator returns whether a slice contains an ordered subset using the given compare function.
func ContextWithAttributes ¶
ContextWithAttributes returns a child of the ctx containing the attributes. All spans created with the returned context and its children will have the attributes set.
func DefaultHttpClient ¶
func DefaultHttpClient(rt http.RoundTripper) *http.Client
func DefaultTransport ¶
func FileExists ¶
FileExists provides a clearer interface for checking if a file exists.
func FilterSlice ¶
FilterSlice filters a slice of elements based on a filter function.
func FromBoolPtr ¶
FromBoolPtr returns the resolved boolean value from the input boolean pointer. For nil pointers, it returns false (i.e. the default value is false when the boolean is unspecified).
func FromBoolTPtr ¶
FromBoolTPtr returns the resolved boolean value from the input boolean pointer. For nil pointers, it returns true (i.e. the default value is true when the boolean is unspecified).
func FromBytePtr ¶
FromBytePtr returns the resolved byte value from the input byte pointer. For nil pointers, it returns 0.
func FromFloat32Ptr ¶
FromFloat32Ptr returns the resolved float32 value from the input float32 pointer. For nil pointers, it returns 0.
func FromFloat64Ptr ¶
FromFloat64Ptr returns the resolved float64 value from the input float64 pointer. For nil pointers, it returns 0.
func FromInt32Ptr ¶
FromInt32Ptr returns the resolved int32 value from the input int32 pointer. For nil pointers, it returns 0.
func FromInt64Ptr ¶
FromInt64Ptr returns the resolved int64 value from the input int64 pointer. For nil pointers, it returns 0.
func FromIntPtr ¶
FromIntPtr returns the resolved int value from the input int pointer. For nil pointers, it returns 0.
func FromNanoseconds ¶
fromNanoSeconds returns milliseconds of a duration for queries in the database.
func FromPythonTime ¶
FromPythonTime returns a time.Time that corresponds to the float style python time which is <seconds>.<fractional_seconds> from unix epoch.
func FromStringPtr ¶
FromStringPtr returns the resolved string value from the input string pointer. For nil pointers, it returns the empty string.
func FromStringPtrSlice ¶
FromStringPtrSlice returns a slice of strings from a slice of string pointers.
func FromTimeDurationPtr ¶
FromTimeDurationPtr returns the resolved time.Duration value from the input time.Duration pointer. For nil pointers, it returns time.Duration(0).
func FromTimePtr ¶
FromTimePtr returns the resolved time.Time value from the input time.Time pointer. For nil pointers, it returns the zero time.
func FromUintPtr ¶
FromUintPtr returns the resolved uint value from the input uint pointer. For nil pointers, it returns 0.
func GetCustomHTTPRetryableClient ¶
func GetCustomHTTPRetryableClient(retry HTTPRetryFunction, delay HTTPDelayFunction) *http.Client
GetCustomHTTPRetryableClient allows you to generate an HTTP client that automatically retries failed request based on the provided custom logic.
func GetCustomHTTPRetryableClientWithTransport ¶
func GetCustomHTTPRetryableClientWithTransport(rt http.RoundTripper, retry HTTPRetryFunction, delay HTTPDelayFunction) *http.Client
GetCustomHTTPRetryableClientWithTransport allows you to generate an HTTP client that automatically retries failed request based on the provided custom logic and HTTP transport.
func GetDefaultHTTPRetryableClient ¶
GetDefaultHTTPRetryableClient provides a retryable client with the default settings. Couple calls to GetHTTPRetryableClient, with defered calls to PutHTTPClient.
func GetHTTPClient ¶
GetHTTPClient produces default HTTP client from the pool, constructing a new client if needed. Always pair calls to GetHTTPClient with defered calls to PutHTTPClient.
func GetHTTPRetryableClient ¶
func GetHTTPRetryableClient(conf HTTPRetryConfiguration) *http.Client
GetHTTPRetryableClient produces an HTTP client that automatically retries failed requests according to the configured parameters. Couple calls to GetHTTPRetryableClient with deferred calls to PutHTTPClient.
func GetOAuth2HTTPClient ¶
GetOAuth2HTTPClient produces an HTTP client that will supply OAuth2 credentials with all requests. There is no validation of the token, and you should always call PutHTTPClient to return the client to the pool when you're done with it.
func GetOauth2CustomHTTPRetryableClient ¶
func GetOauth2CustomHTTPRetryableClient(token string, retry HTTPRetryFunction, delay HTTPDelayFunction) *http.Client
GetOauth2CustomHTTPRetryableClient constructs an HTTP client that supplies OAuth2 credentials with all requests, retrying failed requests automatically according to definitions of the provided functions. There is no validation of the token, and you should always call PutHTTPClient to return the client to the pool when you're done with it.
func GetOauth2DefaultHTTPRetryableClient ¶
GetOauth2DefaultHTTPRetryableClient constructs an HTTP client that supplies OAuth2 credentials with all requests, retrying failed requests automatically according to the default retryable options. There is no validation of the token, and you should always call PutHTTPClient to return the client to the pool when you're done with it.
func GetOauth2HTTPRetryableClient ¶
func GetOauth2HTTPRetryableClient(oauthToken string, conf HTTPRetryConfiguration) *http.Client
GetOauth2HTTPRetryableClient constructs an HTTP client that supplies OAuth2 credentials with all requests, retrying failed requests automatically according to the configuration provided. There is no validation of the token, and you should always call PutHTTPClient to return the client to the pool when you're done with it.
func GetPublicIP ¶
func GetSetDifference ¶
GetSetDifference returns the elements in A that are not in B.
func GetUTCDay ¶
Creates and returns a time.Time corresponding to the start of the UTC day containing the given date.
func GetUTCHour ¶
Creates and returns a time.Time corresponding to the start of the UTC hour containing the given date.
func IsContextError ¶
IsContextError returns true if the given error is due to a context-related error.
func IsTemporaryError ¶
IsTemporaryError returns true if the error object is also a temporary error.
func IsZeroTime ¶
IsZeroTime checks that a time is either equal to golang ZeroTime or UTC ZeroTime.
func JitterInterval ¶
JitterInterval returns a duration that some value between the interval and 2x the interval.
func MD5SumFile ¶
MD5SumFile is the same as ChecksumFile using MD5 as the checksum.
func MakeRandomString ¶
MakeRandomString constructs a hex-encoded random string of a specific length. The size reflects the number of random bytes, not the length of the string.
func MakeSliceBatches ¶
SliceBatches partitions the elems slice into batches with at most maxElemsPerBatch in each batch. If maxElemsPerBatch is not a positive integer, it will make batches of size 1.
func MatchesError ¶
MatchesError returns whether err matches type T.
func NewAttributeSpanProcessor ¶
func NewAttributeSpanProcessor() trace.SpanProcessor
NewAttributeSpanProcessor returns a span processor that adds all the attributes added to the context to every span created from that context and its children.
func NewPaginatedReadCloser ¶
func NewPaginatedReadCloser(ctx context.Context, client *http.Client, resp *http.Response, reqHeader http.Header) *paginatedReadCloser
NewPaginatedReadCloser returns an io.ReadCloser implementation for paginated HTTP responses. It is safe to pass in a non-paginated response, thus the caller need not check for the appropriate header keys. Optionally pass in a header for subsequent page requests, useful if user information such as API keys are required.
func NewRequestReader ¶
func NewRequestReader(req *http.Request) io.ReadCloser
NewRequestReader returns an io.ReadCloser closer for the body of an *http.Request, using a limited reader internally to avoid unbounded reading from the request body. The reader is limited to 16 megabytes.
func NewRequestReaderWithSize ¶
func NewRequestReaderWithSize(req *http.Request, size int64) io.ReadCloser
NewRequestReaderWithSize returns an io.ReadCloser closer for the body of an *http.Request with a user-specified size.
func NewResponseReader ¶
func NewResponseReader(req *http.Response) io.ReadCloser
NewResponseReader returns an io.ReadCloser closer for the body of an *http.Response, using a limited reader internally to avoid unbounded reading from the request body. The reader is limited to 16 megabytes.
func NewResponseReaderWithSize ¶
func NewResponseReaderWithSize(req *http.Response, size int64) io.ReadCloser
NewResponseReaderWithSize returns an io.ReadCloser closer for the body of an *http.Response with a user-specified size.
func NopWriteCloser ¶
func NopWriteCloser(w io.Writer) io.WriteCloser
NopWriteCloser returns a WriteCloser with a no-op Close method wrapping the provided writer w.
func PrintJSON ¶
func PrintJSON(data interface{}) error
PrintJSON marshals the data to a pretty-printed (indented) string and then prints it to standard output.
func PutHTTPClient ¶
PutHTTPClient returns the client to the pool, automatically reconfiguring the transport.
func RandomString ¶
func RandomString() string
RandomString returns a hex-encoded cryptographically random string. This function always returns 16 bytes of randomness encoded in a 32 character string.
func ReadJSON ¶
func ReadJSON(r io.ReadCloser, target interface{}) error
ReadJSON provides an alternate interface to json.Unmarshal that reads data from an io.ReadCloser.
func ReadJSONFile ¶
ReadJSONFile parses json into the target argument from the file located at the specified path.
func ReadYAML ¶
func ReadYAML(r io.ReadCloser, target interface{}) error
ReadYAML provides an alternate interface to yaml.Unmarshal that reads data from an io.ReadCloser.
func ReadYAMLFile ¶
ReadYAMLFile parses yaml into the target argument from the file located at the specified path.
func ReadYAMLFileStrict ¶
ReadYAMLFileStrict is the same as ReadYAMLFile but uses strict unmarshalling.
func ReadYAMLStrict ¶
func ReadYAMLStrict(r io.ReadCloser, target interface{}) error
ReadYAMLStrict is the same as ReadYAML but uses strict unmarshalling.
func Retry ¶
func Retry(ctx context.Context, op RetryableFunc, opts RetryOptions) error
Retry provides a mechanism to retry an operation with exponential backoff and jitter.
func RetryRequest ¶
func RetryRequest(ctx context.Context, r *http.Request, opts RetryRequestOptions) (*http.Response, error)
RetryRequest takes an http.Request and makes the request until it's successful, hits a max number of retries, or times out
func RoundPartOfDay ¶
RoundPartOfDay produces a time value with the hour value rounded down to the most recent interval.
func RoundPartOfHour ¶
RoundPartOfHour produces a time value with the minute value rounded down to the most recent interval.
func RoundPartOfMinute ¶
RoundPartOfMinute produces a time value with the second value rounded down to the most recent interval.
func SHA1SumFile ¶
SHA1SumFile is the same as ChecksumFile using SHA1 as the checksum.
func SetupOauth2CustomHTTPRetryableClient ¶
func SetupOauth2CustomHTTPRetryableClient(token string, retry HTTPRetryFunction, delay HTTPDelayFunction, client *http.Client) *http.Client
SetupOauth2CustomHTTPRetryableClient configures an HTTP client that supplies OAuth2 credentials with all requests, retrying failed requests automatically according to definitions of the provided functions. There is no validation of the token, and you should always call PutHTTPClient to return the client to the pool when you're done with it.
func SetupOauth2HTTPClient ¶
SetupOauth2HTTPClient configures an HTTP client that supplies OAuth2 credentials with all requests. There is no validation of the token, and you should always call PutHTTPClient to return the client to the pool when you're done with it.
func SplitCommas ¶
SplitCommas returns the slice of strings after splitting each string by commas.
func StringMatchesAnyRegex ¶
StringMatchesAnyRegex determines if the string item matches any regex in the slice.
func StringSliceContains ¶
StringSliceContains determines if a string is in a slice.
func StringSliceContainsOrderedPrefixSubset ¶
StringSliceContainsOrderedPrefixSubset returns whether a slice contains an ordered subset of prefixes using strings.HasPrefix.
func StringSliceIntersection ¶
StringSliceIntersection returns the intersecting elements of slices a and b.
func StringSliceSymmetricDifference ¶
StringSliceSymmetricDifference returns only elements not in common between 2 slices (ie. inverse of the intersection).
func ToFloat32Ptr ¶
ToFloat32Ptr returns a pointer to a float32 value.
func ToFloat64Ptr ¶
ToFloat64Ptr returns a pointer to a float64 value.
func ToNanoseconds ¶
ToNanoSeconds returns milliseconds of a duration for queries in the database.
func ToPythonTime ¶
ToPythonTime returns a number in the format that python's time.time() returns as a float with <seconds>.<fractional_seconds>
func ToStringPtrSlice ¶
ToStringPtr returns a slice of string pointers from a slice of strings.
func ToTimeDurationPtr ¶
ToTimeDurationPtr returns a pointer to a time.Duration value.
func UniqueStrings ¶
UniqueStrings takes a slice of strings and returns a new slice with duplicates removed. Order is preserved.
func UnixMilli ¶
UnixMilli returns t as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in nanoseconds in cannot be represented by an int64 (a date before the year 1678 or after 2262). Note that this means the result of calling UnixMilli on the zero Time on the zero Time is undefined. The result does not depend on the location associated with t.
func WriteJSONFile ¶
WriteJSONFile marshals the data into json and writes it into a file at the specified path.
func WriteRawFile ¶
WriteRawFile writes a sequence of byes to a new file created at the specified path.
func WriteYAMLFile ¶
WriteYAMLFile marshals the data into json and writes it into a file at the specified path.
Types ¶
type AlwaysMatch ¶
type AlwaysMatch struct{}
AlwaysMatch provides a FileMatcher implementation that will always match a file or directory.
type FileAlwaysMatch ¶
type FileAlwaysMatch struct{}
FileFileAlwaysMatch provides a FileMatcher implementation that will always match a file, but not a directory.
type FileListBuilder ¶
type FileListBuilder struct { // Include determines which files should be included. This has lower // precedence than the Exclude filter. Include FileMatcher // Exclude determines which files should be excluded from the file list. // This has higher precedence than the Include filter. Exclude FileMatcher // WorkingDir is the base working directory from which to start searching // for files. WorkingDir string // contains filtered or unexported fields }
FileListBuilder provides options to find files within a directory.
func NewFileListBuilder ¶
func NewFileListBuilder(dir string) *FileListBuilder
NewFileListBuilder returns a default FileListBuilder that will match all files (but not directory names) within the given directory dir.
func (*FileListBuilder) Build ¶
func (b *FileListBuilder) Build() ([]string, error)
Build finds all files that pass the include and exclude filters within the working directory. It does not follow symlinks. All files returned are relative to the working directory.
type FileMatcher ¶
FileMatcher represents a type that can match against files and file information to determine if it should be included.
func NewGitIgnoreFileMatcher ¶
func NewGitIgnoreFileMatcher(prefix string, exprs ...string) FileMatcher
NewGitIgnoreFileMatcher returns a FileMatcher that matches the expressions rooted at the given prefix. The expressions should be gitignore ignore expressions: antyhing that would be matched - and therefore ignored by git - is matched.
type HTTPDelayFunction ¶
type HTTPDelayFunction func(index int, req *http.Request, resp *http.Response, err error) time.Duration
HTTPDelayFunction makes it possible to write customizable retry backoff logic, by allowing you to evaluate the previous request and response and return the duration to wait before the next request.
func RetryHTTPDelay ¶
func RetryHTTPDelay(opts RetryOptions) HTTPDelayFunction
RetryHTTPDelay returns the function that generates the exponential backoff delay between retried HTTP requests.
type HTTPRetryConfiguration ¶
type HTTPRetryConfiguration struct { MaxDelay time.Duration BaseDelay time.Duration MaxRetries int TemporaryErrors bool Methods []string Statuses []int Errors []error ErrorStrings []string }
HTTPRetryConfiguration makes it possible to configure the retry semantics for retryable clients. In most cases, construct this object using the NewDefaultHttpRetryConf, which provides reasonable defaults.
func NewDefaultHTTPRetryConf ¶
func NewDefaultHTTPRetryConf() HTTPRetryConfiguration
NewDefaultHTTPRetryConf constructs a HTTPRetryConfiguration object with reasonable defaults.
type HTTPRetryFunction ¶
HTTPRetryFunction makes it possible to write customizable retry logic. Returning true if the request should be retried again and false otherwise.
type Hash ¶
Hash is a wrapper around a hashing algorithm.
func NewSHA256Hash ¶
func NewSHA256Hash() Hash
NewSHA256Hash returns a Hash that uses the SHA256 algorithm.
type MockHandler ¶
type MockHandler struct { Mu sync.Mutex Calls []*url.URL Header map[string][]string Body []byte StatusCode int // contains filtered or unexported fields }
MockHandler implements the http.Handler interface for mock HTTP servers. See the `https://pkg.go.dev/net/http/httptest` for more information on mocking HTTP servers.
func NewMockHandler ¶
func NewMockHandler() *MockHandler
NewMockHandler returns a MockHandler object that can be used as an http.Handler.
func (*MockHandler) GetWriteError ¶
func (h *MockHandler) GetWriteError() error
GetWriteError returns the most recent error from writing to the http.ResponseWriter.
func (*MockHandler) ServeHTTP ¶
func (h *MockHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP is a thread-safe handler for mocking HTTP responses. The request URLs are recorded and the customizable header, body, and status code are all written to the http.ResponseWriter. GetWriteError (see below) returns the most recent write error, if any.
type NeverMatch ¶
type NeverMatch struct{}
NeverMatch provides a FileMatcher implementation that will never match a file or directory.
type RetryOptions ¶
type RetryOptions struct { // MaxAttempts is the total number of times the operation can be attempted. // By default, it is 1 (i.e. no retries). MaxAttempts int // MinDelay is the minimum delay between operation attempts. By default, it // is 100ms. MinDelay time.Duration // MaxDelay is the maximum delay between operation attempts. By default, it // is (MinDelay * 2^MaxAttempts). MaxDelay time.Duration }
RetryOptions defines the policy for retrying an operation. This is typically used with retries that use exponential backoff.
func (*RetryOptions) Validate ¶
func (o *RetryOptions) Validate()
Validate sets defaults for unspecified or invalid options.
It will set min to 100ms if not set. It will set max to (min * 2^attempts) if not set. It will set attempts to 1 if not set.
type RetryRequestOptions ¶
type RetryRequestOptions struct { RetryOptions // RetryOnInvalidBody is a flag that determines whether to retry // when reading the response body fails. RetryOnInvalidBody bool }
RetryRequestOptions specifically are the options when doing a retryable request. It wraps the RetryOptions and adds options on top that are specific to requests.
type RetryableFunc ¶
RetryableFunc is any function that takes no parameters and returns an error, and whether or not the operation can be retried. These functions can be used with util.Retry.
type SafeBuffer ¶
SafeBuffer provides a thread-safe in-memory buffer.
func MakeSafeBuffer ¶
func MakeSafeBuffer(b bytes.Buffer) *SafeBuffer
MakeSafeBuffer returns a thread-safe Read/Write closer that wraps an existing bytes buffer.
func (*SafeBuffer) Close ¶
func (b *SafeBuffer) Close() error
Close is a no-op to satisfy the closer interface.
func (*SafeBuffer) Read ¶
func (b *SafeBuffer) Read(p []byte) (n int, err error)
Read performs a thread-safe in-memory read.
func (*SafeBuffer) String ¶
func (b *SafeBuffer) String() string
String returns the in-memory buffer contents as a string in a thread-safe manner.
type TemporaryError ¶
TemporayError defines an interface for use in retryable HTTP clients to identify certain errors as Temporary.