utils

package
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2021 License: GPL-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 Checksum

func Checksum(data interface{}) []byte

Checksum returns the SHA-1 checksum of the data.

func ConvertCamelCase

func ConvertCamelCase(s string, _case int, sep byte) string

ConvertCamelCase converts a (lower) CamelCase string into various cases. _case must be unicode.Lower or unicode.Upper.

Example usage:

# snake_case
ConvertCamelCase(s, unicode.Lower, '_')

# SCREAMING_SNAKE_CASE
ConvertCamelCase(s, unicode.Upper, '_')

# kebab-case
ConvertCamelCase(s, unicode.Lower, '-')

# SCREAMING-KEBAB-CASE
ConvertCamelCase(s, unicode.Upper, '-')

# other.separator
ConvertCamelCase(s, unicode.Lower, '.')

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 FromUnixMilli

func FromUnixMilli(ms int64) time.Time

FromUnixMilli creates and returns a time.Time value from the given milliseconds since the Unix epoch ms.

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 Key

func Key(name string, sep byte) string

Key returns the name with all Unicode letters mapped to lower case letters, with an additional separator in front of each original upper case letter.

func Name

func Name(t interface{}) string

Name returns the declared name of type t. Name is used in combination with Key to automatically guess an entity's database table and Redis key.

func TableName

func TableName(t interface{}) string

TableName returns the table of t.

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()
}

func UnixMilli

func UnixMilli(t time.Time) int64

UnixMilli returns milliseconds since the Unix epoch of time t.

Types

This section is empty.

Jump to

Keyboard shortcuts

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