Documentation
¶
Index ¶
- Variables
- func APIErrorIs(err error, kind ErrorKind) bool
- func CommonElements(a []string, b []string) []string
- func CompareHashAndPassword(passwordHash, password string) (bool, error)
- func ContextCanceled(ctx context.Context) bool
- func CountLines(s string) (uint, error)
- func Difference(a []string, b []string) []string
- func Dump(data interface{}) *dump
- func EncodeSha1Hex(str string) string
- func EncodeSha256Hex(str string) string
- func EqualStringSlice(a []string, b []string) bool
- func EqualStringSliceNoOrder(a []string, b []string) bool
- func ErrFromRemote(resp *http.Response) error
- func ErrorResponseFromError(err error) []*errorResponse
- func ExponentialBackoff(ctx context.Context, backoff Backoff, condition ConditionFunc) error
- func ExtractPublicKey(privateKeyPEM []byte) ([]byte, error)
- func GenSSHKeyPair(bits int) ([]byte, []byte, error)
- func GoWait(wg *sync.WaitGroup, f func())
- func HTTPError(w http.ResponseWriter, err error) bool
- func HTTPResponse(w http.ResponseWriter, code int, res interface{}) error
- func IsParentPath(parent, p string) bool
- func IsSameOrParentPath(parent, p string) bool
- func Jitter(duration time.Duration, maxFactor float64) time.Duration
- func NewAPIError(kind ErrorKind, options ...APIErrorOption) error
- func NewAPIErrorWrap(kind ErrorKind, err error, options ...APIErrorOption) error
- func NewRemoteError(kind ErrorKind, options ...RemoteErrorOption) error
- func NewTLSConfig(certFile, keyFile, caFile string, insecureSkipVerify bool) (*tls.Config, error)
- func ParseGitURL(us string) (*url.URL, error)
- func PasswordHash(password string) (string, error)
- func PathHierarchy(p string) []string
- func PathList(p string) []string
- func Ptr[T any](v T) *T
- func RemoteErrorIs(err error, kind ErrorKind) bool
- func ValidateName(s string) bool
- type APIDetailedError
- type APIDetailedErrorOption
- type APIError
- type APIErrorOption
- type Backoff
- type ConditionFunc
- type DefaultUUIDGenerator
- type ErrGitKeyNotFound
- type ErrorCode
- type ErrorKind
- type Errors
- type Git
- func (g *Git) ConfigGet(ctx context.Context, args ...string) (string, error)
- func (g *Git) ConfigSet(ctx context.Context, args ...string) (string, error)
- func (g *Git) Output(ctx context.Context, stdin io.Reader, args ...string) ([]byte, error)
- func (g *Git) OutputLines(ctx context.Context, stdin io.Reader, args ...string) ([]string, error)
- func (g *Git) Pipe(ctx context.Context, w io.Writer, r io.Reader, args ...string) error
- type LimitedBuffer
- type RemoteDetailedError
- type RemoteError
- type RemoteErrorOption
- type TestPrefixUUIDGenerator
- type TestUUIDGenerator
- type UUIDGenerator
- type WrapperError
- type WrapperErrorOption
Constants ¶
This section is empty.
Variables ¶
var DefaultBackoff = Backoff{ Steps: 4, Duration: 10 * time.Millisecond, Factor: 5.0, Jitter: 0.1, }
DefaultBackoff is the recommended backoff for a conflict where a client may be attempting to make an unrelated modification to a resource under active management by one or more controllers.
var DefaultRetry = Backoff{ Steps: 5, Duration: 10 * time.Millisecond, Factor: 1.0, Jitter: 0.1, }
DefaultRetry is the recommended retry for a conflict where multiple clients are making changes to the same resource.
var (
ErrValidation = errors.New("validation error")
)
var ErrWaitTimeout = errors.New("timed out waiting for the condition")
ErrWaitTimeout is returned when the condition exited without success.
var FetchFileBackoff = Backoff{ Steps: 4, Duration: 500 * time.Millisecond, Factor: 2.0, Jitter: 0.1, }
Functions ¶
func APIErrorIs ¶ added in v0.7.0
func CommonElements ¶
CommonElements return the common elements in two slices of strings
func CompareHashAndPassword ¶
func ContextCanceled ¶ added in v0.10.0
ContextCanceled returns whether a context is canceled.
func CountLines ¶
func Difference ¶
Difference returns elements in a - b
func EncodeSha1Hex ¶
EncodeSha1Hex generates sha1 from string and returns its hex encoding
func EncodeSha256Hex ¶
EncodeSha1Hex generates sha1 from string and returns its hex encoding
func EqualStringSlice ¶ added in v0.10.0
EqualStringSlice compares two slices of strings, a nil slice is considered an empty one
func EqualStringSliceNoOrder ¶ added in v0.10.0
EqualStringSliceNoOrder compares two slices of strings regardless of their order, a nil slice is considered an empty one
func ErrFromRemote ¶ added in v0.7.0
func ErrorResponseFromError ¶ added in v0.7.0
func ErrorResponseFromError(err error) []*errorResponse
func ExponentialBackoff ¶
func ExponentialBackoff(ctx context.Context, backoff Backoff, condition ConditionFunc) error
ExponentialBackoff repeats a condition check with exponential backoff.
It checks the condition up to Steps times, increasing the wait by multiplying the previous duration by Factor.
If Jitter is greater than zero, a random amount of each duration is added (between duration and duration*(1+jitter)).
If the condition never returns true, ErrWaitTimeout is returned. All other errors terminate immediately.
func ExtractPublicKey ¶
ExtraxtPublicKey extracts the public key from a ssh private key in pem format
func GenSSHKeyPair ¶
GenSSHKeyPair generate an ssh keypair in rsa format, returning the private key (in pem encoding) and the public key (in the OpenSSH base64 format)
func HTTPResponse ¶ added in v0.7.0
func HTTPResponse(w http.ResponseWriter, code int, res interface{}) error
func IsParentPath ¶
IsParentPath returns if the provided parent is parent of p parent and p paths must use slash "/" separators and must be absolute paths
func IsSameOrParentPath ¶
IsParentPath returns if the provided parent the same path as p or a parent of p parent and p paths must use slash "/" separators
func Jitter ¶
Jitter returns a time.Duration between duration and duration + maxFactor * duration.
This allows clients to avoid converging on periodic behavior. If maxFactor is 0.0, a suggested default value will be chosen.
func NewAPIError ¶ added in v0.7.0
func NewAPIError(kind ErrorKind, options ...APIErrorOption) error
func NewAPIErrorWrap ¶ added in v0.10.0
func NewAPIErrorWrap(kind ErrorKind, err error, options ...APIErrorOption) error
func NewRemoteError ¶ added in v0.7.0
func NewRemoteError(kind ErrorKind, options ...RemoteErrorOption) error
func NewTLSConfig ¶
func PasswordHash ¶
func PathHierarchy ¶
func PathList ¶
PathList return a slice of paths from the base path (root exluded as . or / ). I.E. for a path like "path/to/file" or "/path/to/file" it'll return a slice of these elements: "path", "to", "file"
func RemoteErrorIs ¶ added in v0.7.0
func ValidateName ¶
Types ¶
type APIDetailedError ¶ added in v0.10.0
func NewAPIDetailedError ¶ added in v0.10.0
func NewAPIDetailedError(code ErrorCode, options ...APIDetailedErrorOption) *APIDetailedError
type APIDetailedErrorOption ¶ added in v0.10.0
type APIDetailedErrorOption func(e *APIDetailedError)
func WithAPIDetailedErrorDetails ¶ added in v0.10.0
func WithAPIDetailedErrorDetails(details any) APIDetailedErrorOption
type APIError ¶ added in v0.7.0
type APIError struct { *WrapperError Kind ErrorKind DetailedErrors []*APIDetailedError // contains filtered or unexported fields }
func AsAPIError ¶ added in v0.7.0
type APIErrorOption ¶ added in v0.7.0
type APIErrorOption func(e *APIError)
func WithAPIErrorCallerDepth ¶ added in v0.10.0
func WithAPIErrorCallerDepth(depth int) APIErrorOption
func WithAPIErrorDetailedError ¶ added in v0.10.0
func WithAPIErrorDetailedError(ue *APIDetailedError) APIErrorOption
func WithAPIErrorMsg ¶ added in v0.10.0
func WithAPIErrorMsg(format string, args ...interface{}) APIErrorOption
WithAPIErrorMsg adds an internal message to the error. This message could contain sensitive data so it's just for internal logging and will not be sent to the api caller.
type Backoff ¶
type Backoff struct { Duration time.Duration // the base duration Factor float64 // Duration is multiplied by factor each iteration Jitter float64 // The amount of jitter applied each iteration Steps int // Exit with error after this many steps }
Backoff holds parameters applied to a Backoff function.
type ConditionFunc ¶
ConditionFunc returns true if the condition is satisfied, or an error if the loop should be aborted.
type DefaultUUIDGenerator ¶
type DefaultUUIDGenerator struct{}
type ErrGitKeyNotFound ¶
type ErrGitKeyNotFound struct {
Key string
}
func (*ErrGitKeyNotFound) Error ¶
func (e *ErrGitKeyNotFound) Error() string
type Git ¶
func (*Git) OutputLines ¶
type LimitedBuffer ¶
func NewLimitedBuffer ¶
func NewLimitedBuffer(cap int) *LimitedBuffer
type RemoteDetailedError ¶ added in v0.10.0
type RemoteError ¶ added in v0.7.0
type RemoteError struct { Kind ErrorKind DetailedErrors []*RemoteDetailedError }
RemoteError is an error received from a remote call. It's similar to APIError but with another type so it can be distinguished and won't be propagated to the api response.
func AsRemoteError ¶ added in v0.7.0
func AsRemoteError(err error) (*RemoteError, bool)
func (*RemoteError) Error ¶ added in v0.7.0
func (e *RemoteError) Error() string
type RemoteErrorOption ¶ added in v0.10.0
type RemoteErrorOption func(e *RemoteError)
func WithRemoteErrorDetailedError ¶ added in v0.10.0
func WithRemoteErrorDetailedError(ue *RemoteDetailedError) RemoteErrorOption
type TestPrefixUUIDGenerator ¶
type TestPrefixUUIDGenerator struct{ Prefix string }
type TestUUIDGenerator ¶
type TestUUIDGenerator struct{}
type UUIDGenerator ¶
type WrapperError ¶ added in v0.8.0
type WrapperError struct {
// contains filtered or unexported fields
}
Wrapper error is an helper error type that (optionally) wrap an error and add stack information starting at the frame where the error has been created It's meant to be embedded in custom errors to avoid the need to redefine the Error, Unwrap and StackTrace methods.
Example usage:
type CustomError struct { *WrapperError } func NewCustomError(err error) error { return &CustomError{ util.NewWrapperError(err, util.WithWrapperErrorMsg("connection error")), } }
Create the error
if err != nil { return NewCustomError(err) }
Create the error without wrapping another error
return NewCustomError(nil)
Detect error type
var werr *CustomError if errors.As(err, &werr) { fmt.Println("this is a CustomError") }
func NewWrapperError ¶ added in v0.8.0
func NewWrapperError(err error, options ...WrapperErrorOption) *WrapperError
func (*WrapperError) Error ¶ added in v0.8.0
func (w *WrapperError) Error() string
func (*WrapperError) StackTrace ¶ added in v0.8.0
func (w *WrapperError) StackTrace() errors.StackTrace
func (*WrapperError) Unwrap ¶ added in v0.8.0
func (w *WrapperError) Unwrap() error
type WrapperErrorOption ¶ added in v0.10.0
type WrapperErrorOption func(e *WrapperError)
func WithWrapperErrorCallerDepth ¶ added in v0.10.0
func WithWrapperErrorCallerDepth(depth int) WrapperErrorOption
func WithWrapperErrorMsg ¶ added in v0.10.0
func WithWrapperErrorMsg(format string, args ...interface{}) WrapperErrorOption