util

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: Apache-2.0 Imports: 13 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 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 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 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 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