utility

package module
v0.0.0-...-e2121cf Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0 Imports: 34 Imported by: 78

Documentation

Index

Constants

View Source
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).

Variables

View Source
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)

Weekdays contains all valid days of the week.

View Source
var ZeroTime time.Time = time.Unix(0, 0)

ZeroTime represents 0 in epoch time

Functions

func BSONTime

func BSONTime(t time.Time) time.Time

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

func BoolPtrCopy(in *bool) *bool

BoolPtrCopy creates a new pointer with the same value as in.

func ChecksumFile

func ChecksumFile(hash hash.Hash, path string) (string, error)

ChecksumFile returns the checksum of a file given by path using the given hash.

func ConsistentFilepath

func ConsistentFilepath(parts ...string) string

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

func ContainsOrderedSubsetWithComparator[T any](superset, subset []T, compare func(T, T) bool) bool

ContainsOrderedSubsetWithComparator returns whether a slice contains an ordered subset using the given compare function.

func ContextWithAttributes

func ContextWithAttributes(ctx context.Context, attributes []attribute.KeyValue) context.Context

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 DefaultTransport() *http.Transport

func FalsePtr

func FalsePtr() *bool

FalsePtr returns a pointer to a false value.

func FileExists

func FileExists(path string) bool

FileExists provides a clearer interface for checking if a file exists.

func FilterSlice

func FilterSlice[T any](slice []T, filterFunction func(T) bool) []T

FilterSlice filters a slice of elements based on a filter function.

func FromBoolPtr

func FromBoolPtr(in *bool) bool

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

func FromBoolTPtr(in *bool) bool

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

func FromBytePtr(in *byte) byte

FromBytePtr returns the resolved byte value from the input byte pointer. For nil pointers, it returns 0.

func FromFloat32Ptr

func FromFloat32Ptr(in *float32) float32

FromFloat32Ptr returns the resolved float32 value from the input float32 pointer. For nil pointers, it returns 0.

func FromFloat64Ptr

func FromFloat64Ptr(in *float64) float64

FromFloat64Ptr returns the resolved float64 value from the input float64 pointer. For nil pointers, it returns 0.

func FromInt32Ptr

func FromInt32Ptr(in *int32) int32

FromInt32Ptr returns the resolved int32 value from the input int32 pointer. For nil pointers, it returns 0.

func FromInt64Ptr

func FromInt64Ptr(in *int64) int64

FromInt64Ptr returns the resolved int64 value from the input int64 pointer. For nil pointers, it returns 0.

func FromIntPtr

func FromIntPtr(in *int) int

FromIntPtr returns the resolved int value from the input int pointer. For nil pointers, it returns 0.

func FromNanoseconds

func FromNanoseconds(duration time.Duration) int64

fromNanoSeconds returns milliseconds of a duration for queries in the database.

func FromPythonTime

func FromPythonTime(pyTime float64) time.Time

FromPythonTime returns a time.Time that corresponds to the float style python time which is <seconds>.<fractional_seconds> from unix epoch.

func FromStringPtr

func FromStringPtr(in *string) string

FromStringPtr returns the resolved string value from the input string pointer. For nil pointers, it returns the empty string.

func FromStringPtrSlice

func FromStringPtrSlice(in []*string) []string

FromStringPtrSlice returns a slice of strings from a slice of string pointers.

func FromTimeDurationPtr

func FromTimeDurationPtr(in *time.Duration) time.Duration

FromTimeDurationPtr returns the resolved time.Duration value from the input time.Duration pointer. For nil pointers, it returns time.Duration(0).

func FromTimePtr

func FromTimePtr(in *time.Time) time.Time

FromTimePtr returns the resolved time.Time value from the input time.Time pointer. For nil pointers, it returns the zero time.

func FromUintPtr

func FromUintPtr(in *uint) uint

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

func GetDefaultHTTPRetryableClient() *http.Client

GetDefaultHTTPRetryableClient provides a retryable client with the default settings. Couple calls to GetHTTPRetryableClient, with defered calls to PutHTTPClient.

func GetHTTPClient

func GetHTTPClient() *http.Client

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

func GetOAuth2HTTPClient(oauthToken string) *http.Client

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

func GetOauth2DefaultHTTPRetryableClient(oauthToken string) *http.Client

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 GetPublicIP() (string, error)

func GetSetDifference

func GetSetDifference(a, b []string) []string

GetSetDifference returns the elements in A that are not in B.

func GetUTCDay

func GetUTCDay(date time.Time) time.Time

Creates and returns a time.Time corresponding to the start of the UTC day containing the given date.

func GetUTCHour

func GetUTCHour(date time.Time) time.Time

Creates and returns a time.Time corresponding to the start of the UTC hour containing the given date.

func IndexOf

func IndexOf(a []string, toFind string) int

IndexOf returns the first occurrence of a string in a sorted array.

func IsContextError

func IsContextError(err error) bool

IsContextError returns true if the given error is due to a context-related error.

func IsTemporaryError

func IsTemporaryError(err error) bool

IsTemporaryError returns true if the error object is also a temporary error.

func IsZeroTime

func IsZeroTime(t time.Time) bool

IsZeroTime checks that a time is either equal to golang ZeroTime or UTC ZeroTime.

func JitterInterval

func JitterInterval(interval time.Duration) time.Duration

JitterInterval returns a duration that some value between the interval and 2x the interval.

func MD5SumFile

func MD5SumFile(path string) (string, error)

MD5SumFile is the same as ChecksumFile using MD5 as the checksum.

func MakeRandomString

func MakeRandomString(size int) string

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 MatchesError

func MatchesError[T error](err error) bool

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 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

func PutHTTPClient(c *http.Client)

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

func ReadJSONFile(path string, target interface{}) error

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

func ReadYAMLFile(path string, target interface{}) error

ReadYAMLFile parses yaml into the target argument from the file located at the specified path.

func ReadYAMLFileStrict

func ReadYAMLFileStrict(path string, target interface{}) error

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 RetryOptions) (*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

func RoundPartOfDay(n int) time.Time

RoundPartOfDay produces a time value with the hour value rounded down to the most recent interval.

func RoundPartOfHour

func RoundPartOfHour(n int) time.Time

RoundPartOfHour produces a time value with the minute value rounded down to the most recent interval.

func RoundPartOfMinute

func RoundPartOfMinute(n int) time.Time

RoundPartOfMinute produces a time value with the second value rounded down to the most recent interval.

func SHA1SumFile

func SHA1SumFile(path string) (string, error)

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

func SetupOauth2HTTPClient(token string, client *http.Client) *http.Client

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

func SplitCommas(originals []string) []string

SplitCommas returns the slice of strings after splitting each string by commas.

func StringMatchesAnyRegex

func StringMatchesAnyRegex(item string, regexps []string) bool

StringMatchesAnyRegex determines if the string item matches any regex in the slice.

func StringSliceContains

func StringSliceContains(slice []string, item string) bool

StringSliceContains determines if a string is in a slice.

func StringSliceContainsOrderedPrefixSubset

func StringSliceContainsOrderedPrefixSubset(superset, subset []string) bool

StringSliceContainsOrderedPrefixSubset returns whether a slice contains an ordered subset of prefixes using strings.HasPrefix.

func StringSliceIntersection

func StringSliceIntersection(a, b []string) []string

StringSliceIntersection returns the intersecting elements of slices a and b.

func StringSliceSymmetricDifference

func StringSliceSymmetricDifference(a, b []string) ([]string, []string)

StringSliceSymmetricDifference returns only elements not in common between 2 slices (ie. inverse of the intersection).

func ToBoolPtr

func ToBoolPtr(in bool) *bool

ToBoolPtr returns a pointer to a bool value.

func ToBytePtr

func ToBytePtr(in byte) *byte

ToBytePtr returns a pointer to a byte value.

func ToFloat32Ptr

func ToFloat32Ptr(in float32) *float32

ToFloat32Ptr returns a pointer to a float32 value.

func ToFloat64Ptr

func ToFloat64Ptr(in float64) *float64

ToFloat64Ptr returns a pointer to a float64 value.

func ToInt32Ptr

func ToInt32Ptr(in int32) *int32

ToInt32Ptr returns a pointer to an int32 value.

func ToInt64Ptr

func ToInt64Ptr(in int64) *int64

ToInt64Ptr returns a pointer to an int64 value.

func ToIntPtr

func ToIntPtr(in int) *int

ToIntPtr returns a pointer to an int value.

func ToNanoseconds

func ToNanoseconds(duration time.Duration) time.Duration

ToNanoSeconds returns milliseconds of a duration for queries in the database.

func ToPythonTime

func ToPythonTime(t time.Time) float64

ToPythonTime returns a number in the format that python's time.time() returns as a float with <seconds>.<fractional_seconds>

func ToStringPtr

func ToStringPtr(in string) *string

ToStringPtr returns a pointer to a string.

func ToStringPtrSlice

func ToStringPtrSlice(in []string) []*string

ToStringPtr returns a slice of string pointers from a slice of strings.

func ToTimeDurationPtr

func ToTimeDurationPtr(in time.Duration) *time.Duration

ToTimeDurationPtr returns a pointer to a time.Duration value.

func ToTimePtr

func ToTimePtr(in time.Time) *time.Time

ToTimePtr returns a pointer to a time.Time value.

func ToUintPtr

func ToUintPtr(in uint) *uint

ToUintPtr returns a pointer to a uint value.

func TruePtr

func TruePtr() *bool

TruePtr returns a pointer to a true value.

func UniqueStrings

func UniqueStrings(slice []string) []string

UniqueStrings takes a slice of strings and returns a new slice with duplicates removed. Order is preserved.

func UnixMilli

func UnixMilli(t time.Time) int64

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 WriteFile

func WriteFile(path string, data string) error

WriteFile provides a clearer interface for writing string data to a file.

func WriteJSONFile

func WriteJSONFile(fn string, data interface{}) error

WriteJSONFile marshals the data into json and writes it into a file at the specified path.

func WriteRawFile

func WriteRawFile(path string, data []byte) error

WriteRawFile writes a sequence of byes to a new file created at the specified path.

func WriteYAMLFile

func WriteYAMLFile(fn string, data interface{}) error

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.

func (AlwaysMatch) Match

func (m AlwaysMatch) Match(string, os.FileInfo) bool

Match always returns true.

type FileAlwaysMatch

type FileAlwaysMatch struct{}

FileFileAlwaysMatch provides a FileMatcher implementation that will always match a file, but not a directory.

func (FileAlwaysMatch) Match

func (m FileAlwaysMatch) Match(_ string, info os.FileInfo) bool

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

type FileMatcher interface {
	Match(file string, info os.FileInfo) bool
}

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

type HTTPRetryFunction func(index int, req *http.Request, resp *http.Response, err error) bool

HTTPRetryFunction makes it possible to write customizable retry logic. Returning true if the request should be retried again and false otherwise.

type Hash

type Hash struct {
	hash.Hash
}

Hash is a wrapper around a hashing algorithm.

func NewMD5Hash

func NewMD5Hash() Hash

NewMD5Hash returns a Hash that uses the MD5 algorithm.

func NewSHA1Hash

func NewSHA1Hash() Hash

NewSHA1Hash returns a Hash that uses the SHA1 algorithm.

func NewSHA256Hash

func NewSHA256Hash() Hash

NewSHA256Hash returns a Hash that uses the SHA256 algorithm.

func (Hash) Add

func (h Hash) Add(data string)

Add adds data to the hasher.

func (Hash) Sum

func (h Hash) Sum() string

Sum returns the hash sum of the accumulated data.

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.

func (NeverMatch) Match

func (m NeverMatch) Match(string, os.FileInfo) bool

Match always returns false.

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 RetryableFunc

type RetryableFunc func() (canRetry bool, err error)

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

type SafeBuffer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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.

func (*SafeBuffer) Write

func (b *SafeBuffer) Write(p []byte) (n int, err error)

Write performs a thread-safe in-memory write.

type TemporaryError

type TemporaryError interface {
	error
	Temporary() bool
}

TemporayError defines an interface for use in retryable HTTP clients to identify certain errors as Temporary.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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