utils

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: MIT Imports: 12 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppName

func AppName() string

AppName returns the name of the executable that started this program (process).

func BatchSliceOfStrings

func BatchSliceOfStrings(ctx context.Context, keys []string, count int) <-chan []string

BatchSliceOfStrings groups the given keys into chunks of size count and streams them into a returned channel. Panics if count is less than or equal to zero.

func ChanFromSlice

func ChanFromSlice[T any](values []T) <-chan T

ChanFromSlice takes a slice of values and returns a channel from which these values can be received. This channel is closed after the last value was sent.

func Checksum

func Checksum(data interface{}) []byte

Checksum returns the SHA-1 checksum of the data.

func Ellipsize

func Ellipsize(s string, limit int) string

Ellipsize shortens s to <=limit runes and indicates shortening by "...".

func IsContextCanceled

func IsContextCanceled(err error) bool

IsContextCanceled returns whether the given error is context.Canceled.

func IsDeadlock

func IsDeadlock(err error) bool

IsDeadlock returns whether the given error signals serialization failure.

func IsUnixAddr

func IsUnixAddr(host string) bool

IsUnixAddr indicates whether the given host string represents a Unix socket address.

A host string that begins with a forward slash ('/') is considered Unix socket address.

func JoinHostPort

func JoinHostPort(host string, port int) string

JoinHostPort is like its equivalent in net., but handles UNIX sockets as well.

func PrintErrorThenExit

func PrintErrorThenExit(err error, exitCode int)

PrintErrorThenExit prints the given error to os.Stderr and exits with the specified error code.

func Timed

func Timed(start time.Time, callback func(elapsed time.Duration))

Timed calls the given callback with the time that has elapsed since the start.

Timed should be installed by defer:

func TimedExample(logger *zap.SugaredLogger) {
	defer utils.Timed(time.Now(), func(elapsed time.Duration) {
		logger.Debugf("Executed job in %s", elapsed)
	})
	job()
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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