helpers

package
v0.0.0-...-401afe1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const (
	UserGroupAllPerm = 0770
)

Variables

This section is empty.

Functions

func CmdToString

func CmdToString(c cmd.Cmd) string

CmdToString generates a string representation of a command

func DeferIgnoreError

func DeferIgnoreError(f func() error)

DeferIgnoreError is a helper function to ignore errors returned by functions called with defer.

func IgnoreError

func IgnoreError(err error)

IgnoreError is a helper function to deal with errors.

func IsTypeError

func IsTypeError(err error, target error) bool

IsTypeError returns true if the error is of type TypeError or if any of the causes is of the given type. This is different from errors.Is because errors.Is relies on the Is interface being implemented for errors which isn't the case for many errors. This method uses reflect to compare error types.

func NilError

func NilError(err error) string

func PrettyString

func PrettyString(v interface{}) string

PrettyString returns a prettily formatted string of the object.

func RandBytes

func RandBytes(nByte int) (string, error)

RandBytes generates a string with the given number of bytes. The string is base64 so the length is not the same as the number of bytes

func RandString

func RandString(length int) (string, error)

RandString generates a random string of the desired length

func StreamCmdToLogs

func StreamCmdToLogs(c *cmd.Cmd, log logr.Logger)

StreamCmdToLogs streams the output of a command to the logs

func StructToMap

func StructToMap(s any) (map[string]any, error)

StructToMap returns a dictionary mapping fieldNames to values

Types

type ContentType

type ContentType string
const (
	ContentTypeJSON ContentType = "application/json"
	ContentTypeText ContentType = "text/plain"
	ContentTypeHTML ContentType = "text/html"
)

type ListOfErrors

type ListOfErrors struct {
	Causes []error
	Final  error
}

ListOfErrors is used when we want to return more then one error. This happens when we want to keep going and accumulate errors

func (*ListOfErrors) AddCause

func (l *ListOfErrors) AddCause(e error)

AddCause adds an error to the list.

func (*ListOfErrors) Error

func (l *ListOfErrors) Error() string

Error returns a single error wrapping all the errors.

type MatchError

type MatchError func(err error) string

MatchError is a function for matching errors. Returns empty string if no match

func NewTypeErrorMatcher

func NewTypeErrorMatcher(target error) MatchError

NewTypeErrorMatcher creates a new MatchError function that matches errors of the given type.

Jump to

Keyboard shortcuts

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