util

package
v0.0.0-...-614ca16 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(err error, msgAndArgs ...string)

func CheckHandle

func CheckHandle(err error, msgAndArgs ...string) error

func CheckHandleMsg

func CheckHandleMsg(msg string, err error) error

func ConcatStrings

func ConcatStrings(stringsOrSlices ...interface{}) []string

func DefaultString

func DefaultString(strs ...string) string

DefaultString returns the first string that is not empty

func DistinctStrings

func DistinctStrings(strs []string) []string

func FindFileInDirOrAncestors

func FindFileInDirOrAncestors(dir string, filename string) (string, error)

func HashBytesToString

func HashBytesToString(b []byte) string

func HashToStringViaYaml

func HashToStringViaYaml(i interface{}) (string, error)

func HomeDir

func HomeDir() string

func Must

func Must(err error, msgAndArgs ...string)

func Retry

func Retry(attempts int, callback func() error) (err error)

func RetryAfter

func RetryAfter(attempts int, callback func() error, d time.Duration) (err error)

func SortedKeys

func SortedKeys(i interface{}) []string

func StringSliceToMap

func StringSliceToMap(ss ...string) map[string]string

StringSliceToMap converts []string{"a","A", "b", "B"} to map[string]string{"a":"A", "b":"B"}

func TryCatch

func TryCatch(label string, fn func() error) (err error)

Types

type Logger

type Logger interface {
	Log() *logrus.Entry
}

type Prefixer

type Prefixer struct {
	// contains filtered or unexported fields
}

Prefixer implements io.Reader and io.WriterTo. It reads data from the underlying reader and prepends every line with a given string.

func New

func New(r io.Reader, prefix string) *Prefixer

New creates a new instance of Prefixer.

func (*Prefixer) Read

func (r *Prefixer) Read(p []byte) (n int, err error)

Read implements io.Reader. It reads data into p from the underlying reader and prepends every line with a prefix. It does not block if no data is available yet. It returns the number of bytes read into p.

func (*Prefixer) WriteTo

func (r *Prefixer) WriteTo(w io.Writer) (n int64, err error)

type ProgressBar

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

ProgressBar is a thread-safe, simple progress bar

func NewProgressBar

func NewProgressBar(max int) *ProgressBar

NewProgressBar returns a new ProgressBar with the specified maximum

func (*ProgressBar) Add

func (p *ProgressBar) Add(num int, label string) error

Add with increase the current count on the progress bar

func (*ProgressBar) Clear

func (p *ProgressBar) Clear() error

Clear attempts to erase the progress bar.

func (*ProgressBar) Reset

func (p *ProgressBar) Reset()

Reset will reset the clock that is used to calculate current time and the time left.

func (*ProgressBar) SetMax

func (p *ProgressBar) SetMax(num int)

SetMax sets the total number of the progress bar

func (*ProgressBar) SetSize

func (p *ProgressBar) SetSize(size int)

SetSize sets the size of the progress bar.

func (*ProgressBar) SetTheme

func (p *ProgressBar) SetTheme(theme []string)

func (*ProgressBar) SetWriter

func (p *ProgressBar) SetWriter(w io.Writer)

SetWriter will specify a different writer than os.Stdout

type RetriableError

type RetriableError struct {
	Err error
}

func (RetriableError) Error

func (r RetriableError) Error() string

type Tabler

type Tabler interface {
	Headers() []string
	Rows() [][]string
}

Tabler implementations can be rendered as a table.

type TempFile

type TempFile struct {
	Content []byte
	Pattern string
	Path    string
	// contains filtered or unexported fields
}

func NewTempFile

func NewTempFile(pattern string, content []byte) (*TempFile, error)

func (*TempFile) CleanUp

func (t *TempFile) CleanUp() error

type WithLogFielder

type WithLogFielder interface {
	Logger
	WithLogField(name string, value interface{}) WithLogFielder
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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