base

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrChannelIO indicates a channel I/O error
	ErrChannelIO = errors.New("channel IO error")
	// ErrInvalidArg indicates an invalid argument has been encountered, most
	// likely an unexpected nil pointer.
	ErrInvalidArg = errors.New("invalid argument")
	// ErrUnexpectedResult indicates an unexpected result from a operation.
	ErrUnexpectedResult = errors.New("return value of operation invalid")
	// ErrResourceUnavailable indicates an unsuccessful attempt to access an
	// unavailable resource.
	ErrResourceUnavailable = errors.New("resource unavailable")
	// ErrItemNotFound indicates that the retrieval of a queryable resource from
	// a collection produced an empty set.
	ErrItemNotFound = errors.New("item not found")
	// ErrNotImplemented indicates that functionality is not available.
	ErrNotImplemented = errors.New("not implemented (yet)")
	// ErrTimeoutExceeded indicates, that a timeout has been exceeded
	ErrTimeoutExceeded = errors.New("timeout exceeded")
	// ErrIntentional indicates, that an error has been intentionally
	// generated; mostly used in tests.
	ErrIntentional = errors.New("intentional")
	// ErrNetClosing is returned when a network descriptor is used after
	// it has been closed. Keep this string consistent because of issue
	// #4373: since historically programs have not been able to detect
	// this error, they look for the string.
	ErrNetClosing = errors.New("use of closed network connection")
)

Functions

func BitFieldContains

func BitFieldContains[T constraints.Integer](bf T, vals ...T) bool

BitFieldContains checks, whether all vals are contained in the field bf.

func BitFieldUnset

func BitFieldUnset[T constraints.Integer](bf T, vals ...T) T

BitFieldUnset unsets vals in the field bf.

func CanonicalAbsPath

func CanonicalAbsPath(path string) (string, error)

CanonicalAbsPath returns an absolute representation of to path after potentially replacing environment variable references. See also filepath.Abs()

func CanonicalPath

func CanonicalPath(path string) string

CanonicalPath returns the shortest path name equivalent to path after potentially replacing environment variable references. See also filepath.Clean()

func IsIPv4

func IsIPv4(address string) bool

IsIPv4 returns true, if address contains an IPv4 address, false otherwise.

func IsIPv6

func IsIPv6(address string) bool

IsIPv6 returns true, if address contains an IPv6 address, false otherwise.

func MapKeys

func MapKeys[M ~map[K]V, K comparable, V any](m M, options ...MapOption[K]) []K

MapKeys returns the keys of the map m.

func MapValues

func MapValues[M ~map[K]V, K comparable, V any](m M, options ...MapOption[V]) []V

MapValues returns the values of the map m.

func MergeArray

func MergeArray[T comparable](a, b []T) []T

MergeArray always returns a new array with the merged, unique values of the arrays a and b.

func MergeMapExt

func MergeMapExt[K comparable, V any](a, b map[K]V,
	mergeValue func(key K, valA, valB V) V) map[K]V

MergeMapExt always returns a new map containing the result of merging maps a and b. If the same key exists in both maps, mergeValue is called to decide the resulting value for the key.

func Must

func Must[T any](o T, err error) T

Must is a simple wrapper implementing the commonly user "Must"-pattern in Go, e.g., regexp.MustCompilePOSIX(). see https://stackoverflow.com/a/73584801

func MustCanonicalAbsPath

func MustCanonicalAbsPath(path string) string

MustCanonicalAbsPath returns an absolute representation of to path after potentially replacing environment variable references. See also filepath.Abs() NOTE This function panics in the unlikely event, that an absolute path cannot be derived.

func NewErrChannelIO

func NewErrChannelIO(format string, a ...any) error

NewErrChannelIO creates a new error wrapped by ErrChannelIO.

func NewErrIntentional

func NewErrIntentional(format string, a ...any) error

NewErrIntentional creates a new error wrapped by ErrIntentional.

func NewErrInvalidArg

func NewErrInvalidArg(format string, a ...any) error

NewErrInvalidArg creates a new error wrapped by ErrInvalidArg.

func NewErrItemNotFound

func NewErrItemNotFound(format string, a ...any) error

NewErrItemNotFound creates a new error wrapped by ErrItemNotFound.

func NewErrNetClosing

func NewErrNetClosing(format string, a ...any) error

NewErrNetClosing creates a new error wrapped by ErrNetClosing.

func NewErrNotImplemented

func NewErrNotImplemented(format string, a ...any) error

NewErrNotImplemented creates a new error wrapped by ErrNotImplemented.

func NewErrResourceUnavailable

func NewErrResourceUnavailable(format string, a ...any) error

NewErrResourceUnavailable creates a new error wrapped by ErrResourceUnavailable.

func NewErrTimeoutExceeded

func NewErrTimeoutExceeded(format string, a ...any) error

NewErrTimeoutExceeded creates a new error wrapped by ErrTimeoutExceeded.

func NewErrUnexpectedResult

func NewErrUnexpectedResult(format string, a ...any) error

NewErrUnexpectedResult creates a new error wrapped by ErrUnexpectedResult.

func OpenBrowser

func OpenBrowser(rawURL string) error

OpenBrowser ... see https://gist.github.com/hyg/9c4afcd91fe24316cbf0

func RoundedDuration

func RoundedDuration(d time.Duration, decimal int) time.Duration

RoundedDuration returns a duration with the corresponding number of decimal places.

func UnmarshalWithAlteredTags

func UnmarshalWithAlteredTags[T any](fieldNameTags map[string]string, unmarshalF func([]byte, any) error, data []byte) (T, error)

UnmarshalWithAlteredTags ...

Types

type MapOption

type MapOption[T any] func(*mapOptionArg[T])

A MapOption allows for additional configuration of the MapKeys() and MapValues() functions.

func MapFilterOption

func MapFilterOption[T any](filterFunc func(T) bool) MapOption[T]

MapFilterOption sets an optional filter to be applied to the keys or values returned by MapKeys() or MapValues().

func MapSortOption

func MapSortOption[T any](lessFunc func([]T, int, int) bool) MapOption[T]

MapFilterOption allows for an optional sorting of the keys or values returned by MapKeys() or MapValues().

Jump to

Keyboard shortcuts

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