utils

package
v0.5.502 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Colors = struct {
	reset   string
	Red     string
	Green   string
	Yellow  string
	Orange  string
	Blue    string
	Magenta string
	Cyan    string
	Gray    string
	White   string
}{

	Red:     "\033[31m",
	Green:   "\033[32m",
	Yellow:  "\033[33m",
	Orange:  "\033[38;5;208m",
	Blue:    "\033[34m",
	Magenta: "\033[35m",
	Cyan:    "\033[36m",
	Gray:    "\033[37m",
	White:   "\033[97m",
	// contains filtered or unexported fields
}

Functions

func Colored

func Colored(color string, a ...any) string

func Contains

func Contains[T comparable](slice []T, item T) bool

func DurationRoundBy added in v0.5.5

func DurationRoundBy(duration time.Duration, n int64) time.Duration

func Flatten

func Flatten[T any](nested [][]*T) []*T

func NumLen added in v0.5.5

func NumLen[T Number](n T) T

func PrettyJSONMarshal added in v0.5.5

func PrettyJSONMarshal(v interface{}, maxItems int, prefix, indent string) []byte

func PrintAndExit

func PrintAndExit(message string)

func PrintErr

func PrintErr(err error)

func PrintErrAndExit

func PrintErrAndExit(err error)

func PrintfC

func PrintfC(color string, format string, a ...any)

func PrintlnC

func PrintlnC(color string, a ...any)

func RandomValueCycle added in v0.5.0

func RandomValueCycle[Value any](values []Value, localRand *rand.Rand) func() Value

RandomValueCycle returns a function that cycles through the provided slice of values in a random order. Each call to the returned function will yield a value from the slice. The order of values is determined by the provided random number generator.

The returned function will cycle through the values in a random order until all values have been returned at least once. After all values have been returned, the function will reset and start cycling through the values in a random order again. The returned function isn't thread-safe and should be used in a single-threaded context.

Types

type Number added in v0.5.5

type Number interface {
	int | int8 | int16 | int32 | int64
}

type TruncatedMarshaller added in v0.5.5

type TruncatedMarshaller struct {
	Value    interface{}
	MaxItems int
}

func (TruncatedMarshaller) MarshalJSON added in v0.5.5

func (t TruncatedMarshaller) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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