goutils

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2025 License: MIT Imports: 3 Imported by: 3

README

goutils

Build codecov Go Report Card Go Reference

Just some convenience functions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MergeChannels

func MergeChannels[T any](cs ...chan T) chan T

func Pack added in v0.4.0

func Pack(a, b int64) int64

Pack stores two ints in one. Go stores ints as 8 bytes so we store the first int in the bottom four and the second in the top four. This has a limitation of only being able to store a max value of 4294967295.

func RandomString added in v0.4.0

func RandomString(n int) string

RandomString returns a cases sensitive random string of the given length. The randonSource and character array are in the function to avoid data races. At this time its overkill to store them in a type but this can be done in the future if necessary.

func RemoveElementFromArray

func RemoveElementFromArray[T any](slice []T, s int) []T

RemoveElementFromArray does just that, if an index is passed in that is larger than the slice length then the original slice is returned.

func Unpack added in v0.4.0

func Unpack(x int64) (int64, int64)

Unpack extracts two ints stored in one. 0xFFFFFFFF represents 32 bits of 1s so we AND them to x to get the first number, then we shift and AND to get the second number.

Types

type Broadcast added in v0.7.0

type Broadcast struct {
	Subscribers []chan any
	Lock        sync.RWMutex
}

func NewBroadcast added in v0.7.0

func NewBroadcast() *Broadcast

func (*Broadcast) Broadcast added in v0.7.0

func (b *Broadcast) Broadcast(message any)

func (*Broadcast) Shutdown added in v0.7.0

func (b *Broadcast) Shutdown()

func (*Broadcast) Subscribe added in v0.7.0

func (b *Broadcast) Subscribe() chan any

func (*Broadcast) Unsubscribe added in v0.7.0

func (b *Broadcast) Unsubscribe(unsubscriber chan any)

Jump to

Keyboard shortcuts

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