Documentation ¶
Overview ¶
Package common holds generic functionality that is common to multiple packages.
Index ¶
- func Keys[K comparable, V any](m map[K]V) []K
- func Panicf(format string, args ...any)
- func Pause()
- func ReplaceEnvVars(str string) string
- func ReplaceTildeInDir(dir string) string
- func SendNoBlock[T any](c chan T, value T) (status int)
- func SortedKeys[K constraints.Ordered, V any](m map[K]V) []K
- func TrySend[T any](c chan T, value T) (ok bool)
- func UniqueId() string
- func WalkDirWithSymbolicLinks(root string, dirFunc fs.WalkDirFunc) error
- type ArrayFlag
- type Latch
- type LatchWithValue
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Keys ¶ added in v0.6.5
func Keys[K comparable, V any](m map[K]V) []K
Keys returns the keys of a map in the form of a slice.
func Panicf ¶ added in v0.9.0
Panicf panics with an error constructed with the given format and args.
func Pause ¶ added in v0.9.0
func Pause()
Pause the current goroutine, it waits forever on a channel. Used for testing.
func ReplaceEnvVars ¶ added in v0.10.0
ReplaceEnvVars makes bash-like substitutions of environment variables, when preceded by '$'.
Example: if `HOME=/home/user` and `F=abc`, then `SubstituteEnvVars("${HOME}/$F/def")` returns the string `"/home/user/abc/def"`.
func ReplaceTildeInDir ¶ added in v0.7.1
ReplaceTildeInDir by the user's home directory. Returns dir if it doesn't start with "~".
It may panic with an error if `dir` has an unknown user (e.g: `~unknown/...`)
func SendNoBlock ¶ added in v0.9.0
SendNoBlock tries to send value through the channel. It returns 0 if the value was sent, 1 if sending it would block (channel buffer full) or 2 if the channel `c` was closed.
func SortedKeys ¶
func SortedKeys[K constraints.Ordered, V any](m map[K]V) []K
SortedKeys returns the sorted keys of a map in the form of a slice.
func TrySend ¶ added in v0.9.0
TrySend tries to send value through the channel. It returns false if it failed, presumably because the channel is closed.
func WalkDirWithSymbolicLinks ¶ added in v0.7.0
func WalkDirWithSymbolicLinks(root string, dirFunc fs.WalkDirFunc) error
WalkDirWithSymbolicLinks is similar filepath.WalkDir, but it follows symbolic links. It also checks for infinite loops in symbolic links, and ignore them.
Types ¶
type ArrayFlag ¶ added in v0.9.0
type ArrayFlag []string
ArrayFlag implements a flag type that append repeated settings into an array (slice). TODO: make it generic and accept `float64` and `int`.
type Latch ¶ added in v0.9.0
type Latch struct {
// contains filtered or unexported fields
}
Latch implements a "latch" synchronization mechanism.
A Latch is a signal that can be waited for until it is triggered. Once triggered it never changes state, it's forever triggered.
type LatchWithValue ¶ added in v0.9.0
type LatchWithValue[T any] struct { // contains filtered or unexported fields }
LatchWithValue implements a "latch" synchronization mechanism, with a value associated with the triggering of the latch.
A LatchWithValue is a signal that can be waited for until it is triggered. Once triggered it never changes state, it's forever triggered.
func NewLatchWithValue ¶ added in v0.9.0
func NewLatchWithValue[T any]() *LatchWithValue[T]
NewLatchWithValue returns an un-triggered latch.
func (*LatchWithValue[T]) Test ¶ added in v0.9.0
func (l *LatchWithValue[T]) Test() bool
Test checks whether the latch has been triggered.
func (*LatchWithValue[T]) Trigger ¶ added in v0.9.0
func (l *LatchWithValue[T]) Trigger(value T)
Trigger latch and saves the associated value.
func (*LatchWithValue[T]) Wait ¶ added in v0.9.0
func (l *LatchWithValue[T]) Wait() T
Wait waits for the latch to be triggered.
type Set ¶
type Set[T comparable] map[T]struct{}
Set implements a Set for the key type T.
func MakeSet ¶
func MakeSet[T comparable](size ...int) Set[T]
MakeSet returns an empty Set of the given type. Size is optional, and if given will reserve the expected size.
func SetWithValues ¶ added in v0.10.0
func SetWithValues[T comparable](values ...T) Set[T]
SetWithValues creates a new Set initialized with the given `values`.