utils

package
v0.0.0-...-f0e227c Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 12 Imported by: 0

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.

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 Fatal

func Fatal(err error)

Fatal panics with the given error.

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

func JoinHostPort

func JoinHostPort(host string, port int) string

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

func MaxInt

func MaxInt(x, y int) int

MaxInt returns the larger of the given integers.

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