util

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 12 Imported by: ? 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 CopyInts

func CopyInts(input []int) []int

CopyInts copies a slice of ints.

func InTerminal

func InTerminal() bool

InTerminal determines whether we're running in a terminal or not.

Implementation from https://rosettacode.org/wiki/Check_output_device_is_a_terminal#Go.

func PrettyDuration

func PrettyDuration(duration time.Duration) string

PrettyDuration returns a human-formatted duration string given an golang duration value.

func PrettyRate

func PrettyRate(count int64, duration time.Duration) string

PrettyRate returns a human-formatted rate from a count and a duration.

func RandomString

func RandomString(prefix string, length int) string

RandomString returns a random string with the argument length.

Adapted from the example in https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go.

func SameElements

func SameElements(slice1 []int, slice2 []int) bool

SameElements determines whether two int slices have the same elements (in any order).

func ShuffledKeys

func ShuffledKeys(input map[int]int, seedStr string) []int

ShuffledKeys returns a shuffled version of the keys in the argument map. The provided seedStr is hashed and used to seed the random number generator.

func SortedKeys

func SortedKeys(input map[int]int) []int

SortedKeys returns the keys of the argument, sorted by value.

func SortedKeysByValue

func SortedKeysByValue(input map[int]int, asc bool, keySorter KeySorter) []int

SortedKeysByValue returns the keys in a map, sorted by the map values.

func TestKafkaAddr

func TestKafkaAddr() string

TestKafkaAddr returns a kafka bootstrap address for unit testing purposes.

func TestKafkaConn

func TestKafkaConn(ctx context.Context, t *testing.T) *kafka.Conn

TestKafkaConn returns a kafka-go connection for unit testing purposes.

func TestKafkaContollerConn

func TestKafkaContollerConn(ctx context.Context, t *testing.T) *kafka.Conn

TestKafkaContollerConn returns a kafka-go connection to the cluster controller for unit testing purposes.

func TestZKAddr

func TestZKAddr() string

TestZKAddr returns a zookeeper address for unit testing purposes.

func TruncateStringMiddle

func TruncateStringMiddle(input string, maxLen int, suffixLen int) (string, int)

TruncateStringMiddle truncates a string by replacing characters in the middle with "..." if needed.

func TruncateStringSuffix

func TruncateStringSuffix(input string, maxLen int) (string, int)

TruncateStringSuffix truncates a string by replacing the trailing characters with "..." if needed.

Types

type KeySorter

type KeySorter func(map[int]int) []int

KeySorter is a type for a function that sorts integer keys based on their values in a map.

Jump to

Keyboard shortcuts

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