util

package
v0.0.0-...-142450a Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const SIZE int = 2 ^ 20

Variables

This section is empty.

Functions

func B64Dec

func B64Dec(src []byte) ([]byte, error)

B64Dec decodes a base64-encoded string (represented as byte array) into a byte array.

func Contains

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

func MkThrottler

func MkThrottler(timeout int64) *ipThrottle

Returns a throttler that can memorize up to 2^20 IP addresses. Can be queried to check if an IP address was stored within the timeout window. If size is exceeded, the odlest IP address that was stored will be discarded first.

Types

type Elem

type Elem[T comparable] interface {
	ToComparable() T
}

type Promise

type Promise[T any] interface {
	// Fullfil the promise. [Get] will unblock (when called already) or succeed
	// (when called later).
	Fulfill(T)
	// Cancel a promise. Subsequent calls to [Get] will return T's null value.
	Reject()
	// Return the value of the promise. Will only return the result the promise
	// was fullfilled with exactly once. Afterwards, it will return the null
	// value. Call will block on unfullfilled promise.
	Get() T
}

An interface to implement promises that can be created and fullfilled later.

func Fullfilled

func Fullfilled[T any](val T) Promise[T]

Return a promise that is already fullfilled with the given value.

func NewPromise

func NewPromise[T any]() Promise[T]

Create a new promise.

func Rejected

func Rejected[T any]() Promise[T]

Return a rejected promise.

type Set

type Set[T comparable] interface {
	Has(Elem[T]) Elem[T]
	HasKey(T) Elem[T]
	Add(Elem[T])
	Rm(Elem[T]) Elem[T]
	Size() int
}

func MkSet

func MkSet[T comparable]() Set[T]

Jump to

Keyboard shortcuts

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