utils

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 11 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

Overview

Package utils provides utility functions for the application

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllContains

func AllContains[T comparable](slices1, slices2 []T) bool

AllContains checks if all of the slices contain a specific element

func AnyContains

func AnyContains[T comparable](slices1, slices2 []T) bool

AnyContains checks if any of the slices contains a specific element

func Contains

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

Contains checks if a slice contains a specific element

func CreateFileWithDir

func CreateFileWithDir(filePath string) (*os.File, error)

CreateFileWithDir creates a file with the directory

func GenerateRandomBytes

func GenerateRandomBytes(size int) ([]byte, error)

GenerateRandomBytes generates a random byte slice of the given size.

func GenerateRandomString

func GenerateRandomString(length int) (string, error)

GenerateRandomString generates a random string of the given length

func GenerateRandomStringWithCharset

func GenerateRandomStringWithCharset(length int, charset string) string

GenerateRandomStringWithCharset generates a random string of the given length with the given charset.

func GenerateUniqueID

func GenerateUniqueID() string

GenerateUniqueID generates a unique ID

func NewSyncMapFromMap

func NewSyncMapFromMap(m map[string]any) *sync.Map

NewSyncMapFromMap creates a new sync.Map from a map

func RemoveElement

func RemoveElement[T comparable](slice []T, elem T) []T

RemoveElement removes an element from a slice

Types

type Broadcaster

type Broadcaster[T any] struct {
	// contains filtered or unexported fields
}

Broadcaster is a type that broadcasts a value to multiple subscribers.

func NewBroadcaster

func NewBroadcaster[T any]() *Broadcaster[T]

NewBroadcaster creates a new Broadcaster.

func (*Broadcaster[T]) Broadcast

func (b *Broadcaster[T]) Broadcast(value T) <-chan struct{}

Broadcast broadcasts a value to all subscribers.

func (*Broadcaster[T]) Close

func (b *Broadcaster[T]) Close()

Close closes the Broadcaster.

func (*Broadcaster[T]) Subscribe

func (b *Broadcaster[T]) Subscribe() <-chan T

Subscribe subscribes to the Broadcaster.

func (*Broadcaster[T]) Unsubscribe

func (b *Broadcaster[T]) Unsubscribe(ch chan T)

Unsubscribe unsubscribes from the Broadcaster.

type DelayedTransport

type DelayedTransport struct {
	Transport http.RoundTripper
	Delay     time.Duration
}

DelayedTransport is an http.RoundTripper that introduces a delay before

func (*DelayedTransport) RoundTrip

func (d *DelayedTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a single HTTP transaction

Jump to

Keyboard shortcuts

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