util

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseAll added in v0.4.21

func CloseAll(closers ...io.Closer) error

CloseAll calls Close() on every closer, returning the err from the first one that returns a non-nil error.

func CreateRootTempDir added in v0.5.50

func CreateRootTempDir() error

CreateRootTempDir - call only once from root command

func DirEmpty added in v0.5.0

func DirEmpty(path string) bool

func DirExists added in v0.5.0

func DirExists(path string) bool

func ExitCode added in v0.4.31

func ExitCode(err error) int

Returns the exit code from an error if the error is an exec.ExitError, or -1 if the err is non-nil, or 0 otherwise.

func FileExists added in v0.4.56

func FileExists(path string) bool

func ForEachLine added in v0.5.0

func ForEachLine(path string, fn func(line string) bool) error

func ForEachReaderLine added in v0.5.9

func ForEachReaderLine(r io.Reader, fn func(line string) bool) error

func GenericGet added in v0.5.7

func GenericGet(m map[string]interface{}, path string) interface{}

func GenericSet added in v0.5.7

func GenericSet(mp *map[string]interface{}, path string, value interface{})

func GetRootTempDir added in v0.5.50

func GetRootTempDir() string

GetRootTempDir - return the absolute path to the root temp dir

func GetTempDirPath added in v0.5.54

func GetTempDirPath() (string, error)

GetTempDirPath - return a unique absolute path for a dir

func GetTempFilePath added in v0.5.50

func GetTempFilePath(filename string) (string, error)

GetTempFilePath - return a unique absolute path for a file with filename

func Git

func Git(arg ...string) (string, error)

func Must added in v0.4.22

func Must(err error)

Must panics if err is non-nil

func MustReadJSONFile added in v0.4.38

func MustReadJSONFile(filename string) *jnode.Node

func PropagateCloseError added in v0.4.21

func PropagateCloseError(closer io.Closer, f func() error) (err error)

PropagateCloseError calls f then calls closer.Close(), returning the error from Close() if f did not return an error. Errors from Close() when writing can return important errors that should not be thrown away.

func ReadJSONFile added in v0.4.36

func ReadJSONFile(filename string) (*jnode.Node, error)

func RemoveJNodeElementsIf added in v0.4.34

func RemoveJNodeElementsIf(n *jnode.Node, f func(*jnode.Node) bool) *jnode.Node

func RemoveJNodeEntriesIf added in v0.4.38

func RemoveJNodeEntriesIf(n *jnode.Node, f func(key string, value *jnode.Node) bool) *jnode.Node

func RemoveRootTempDir added in v0.5.50

func RemoveRootTempDir() string

RemoveRootTempDir - remove the root tmp dir and all subdirs and files, should be called on exit

func Size added in v0.5.9

func Size(n uint64) string

func StringSliceContains

func StringSliceContains(s []string, t string) bool

func TempFile added in v0.4.55

func TempFile(pattern string) (string, error)

func TruncateRight added in v0.4.36

func TruncateRight(s string, m int) string

Replaces newlines in s with spaces and truncates with "..." if the len(s) is more than m. The resulting string will always be m characters or less.

Types

type AtomicFileWriter added in v0.5.44

type AtomicFileWriter struct {
	Temp *os.File
	// contains filtered or unexported fields
}

func NewAtomicFileWriter added in v0.5.44

func NewAtomicFileWriter(path string) (*AtomicFileWriter, error)

Creates a file writer that writes to a temporary file and can rename it to a target file when done. The temp file is created in the same directory as the target file; the rename operation should be atmoic in this case.

func (*AtomicFileWriter) Close added in v0.5.44

func (a *AtomicFileWriter) Close() error

Closes and deletes the tempfile unless it has already been renamed.

func (*AtomicFileWriter) Rename added in v0.5.44

func (a *AtomicFileWriter) Rename() error

Closes and renames the temp file.

func (*AtomicFileWriter) Write added in v0.5.44

func (a *AtomicFileWriter) Write(p []byte) (int, error)

type Cache added in v0.4.39

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

A simple-minded not-scalable LFU cache.

func NewCache added in v0.4.39

func NewCache(max int) *Cache

func (*Cache) Contains added in v0.4.39

func (c *Cache) Contains(key string) bool

func (*Cache) Get added in v0.4.39

func (c *Cache) Get(key string, fill func(string) interface{}) interface{}

func (*Cache) Put added in v0.4.39

func (c *Cache) Put(key string, v interface{})

type StringSet added in v0.4.7

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

func NewStringSet added in v0.4.7

func NewStringSet() *StringSet

func NewStringSetWithValues added in v0.4.15

func NewStringSetWithValues(values []string) *StringSet

func (*StringSet) Add added in v0.4.7

func (ss *StringSet) Add(s string) bool

Adds s to the set and returns true if the string wasn't already present

func (*StringSet) AddAll added in v0.4.7

func (ss *StringSet) AddAll(values ...string) *StringSet

func (*StringSet) Contains added in v0.4.7

func (ss *StringSet) Contains(s string) bool

func (*StringSet) Get added in v0.4.30

func (ss *StringSet) Get(i int) string

func (*StringSet) Len added in v0.4.30

func (ss *StringSet) Len() int

func (*StringSet) MarshalJSON added in v0.4.30

func (ss *StringSet) MarshalJSON() ([]byte, error)

func (*StringSet) Reset added in v0.4.30

func (ss *StringSet) Reset()

func (*StringSet) Values added in v0.4.7

func (ss *StringSet) Values() []string

Jump to

Keyboard shortcuts

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