lib

package
v1.999.330 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 28 Imported by: 25

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultBufferLength = 4096
)

Functions

func EmitDeprecation added in v1.999.330

func EmitDeprecation(w io.Writer, name, replacement, url string)

EmitDeprecation writes a deprecation warning at most once per name. If w is nil, os.Stderr is used.

func GenerateSelfSignedCert

func GenerateSelfSignedCert(org string, hosts ...string) (tls.Certificate, error)

GenerateSelfSignedCert

func GetHostname added in v1.999.310

func GetHostname() string

func HashString64 added in v1.999.330

func HashString64(s string) uint64

HashString64 returns a 64-bit FNV-1a hash of s. Used for distributing items across shards or queues. The algorithm is fixed so the same string always produces the same value across processes and across versions.

func PanicOrigin added in v1.999.330

func PanicOrigin() string

PanicOrigin returns "function[file:line]" a panic came from. Call it from the deferred recover.

func RandomString

func RandomString(length int) string

RandomString

func Recover

func Recover() bool

func ReleaseBuffer

func ReleaseBuffer(b *Buffer)

ReleaseBuffer

func ReleaseTimer

func ReleaseTimer(t *time.Timer)

ReleaseTimer

func TakeTimer

func TakeTimer() *time.Timer

TakeTimer

func Verbose added in v1.999.330

func Verbose() bool

Types

type BiMap added in v1.999.310

type BiMap[A comparable, B comparable] struct {
	// contains filtered or unexported fields
}

func (*BiMap[A, B]) DeleteA added in v1.999.310

func (bm *BiMap[A, B]) DeleteA(a A)

func (*BiMap[A, B]) DeleteB added in v1.999.310

func (bm *BiMap[A, B]) DeleteB(b B)

func (*BiMap[A, B]) GetA added in v1.999.310

func (bm *BiMap[A, B]) GetA(b B) (A, bool)

func (*BiMap[A, B]) GetB added in v1.999.310

func (bm *BiMap[A, B]) GetB(a A) (B, bool)

func (*BiMap[A, B]) ListA added in v1.999.310

func (bm *BiMap[A, B]) ListA() []A

func (*BiMap[A, B]) ListB added in v1.999.310

func (bm *BiMap[A, B]) ListB() []B

func (*BiMap[A, B]) Set added in v1.999.310

func (bm *BiMap[A, B]) Set(a A, b B)

type Buffer

type Buffer struct {
	B []byte
	// contains filtered or unexported fields
}

Buffer

func CompressGZIP

func CompressGZIP(src *Buffer, preallocate uint, level int) (dst *Buffer, err error)

CompressGZIP level: 0 - default, 1 - best speed, 2 - best size

func CompressLZW

func CompressLZW(src *Buffer, preallocate uint) (dst *Buffer, err error)

CompressLZW

func CompressZLIB

func CompressZLIB(src *Buffer, preallocate uint) (dst *Buffer, err error)

CompressZLIB

func DecompressGZIP

func DecompressGZIP(src *Buffer, skip uint, limit int) (dst *Buffer, err error)

func DecompressLZW

func DecompressLZW(src *Buffer, skip uint, limit int) (dst *Buffer, err error)

func DecompressZLIB

func DecompressZLIB(src *Buffer, skip uint, limit int) (dst *Buffer, err error)

func TakeBuffer

func TakeBuffer() *Buffer

TakeBuffer

func (*Buffer) Allocate

func (b *Buffer) Allocate(n int)

Allocate

func (*Buffer) Append

func (b *Buffer) Append(v []byte)

Append

func (*Buffer) AppendByte

func (b *Buffer) AppendByte(v byte)

AppendByte

func (*Buffer) AppendString

func (b *Buffer) AppendString(s string)

AppendString

func (*Buffer) Cap

func (b *Buffer) Cap() int

func (*Buffer) Extend

func (b *Buffer) Extend(n int) []byte

Extend

func (*Buffer) Len

func (b *Buffer) Len() int

Len

func (*Buffer) Read

func (b *Buffer) Read(v []byte) (n int, err error)

func (*Buffer) ReadDataFrom

func (b *Buffer) ReadDataFrom(r io.Reader, limit int) (int, error)

ReadDataFrom

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset

func (*Buffer) Set

func (b *Buffer) Set(v []byte)

Set

func (*Buffer) String

func (b *Buffer) String() string

String

func (*Buffer) Write

func (b *Buffer) Write(v []byte) (n int, err error)

func (*Buffer) WriteDataTo

func (b *Buffer) WriteDataTo(w io.Writer) error

WriteDataTo

type Dispatcher added in v1.999.330

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

Dispatcher decouples producers from a single handler through a bounded MPSC queue and a worker that runs only while there is work: it is spawned on Push when idle and exits once the queue drains, so an idle dispatcher holds no goroutine (like a sleeping process). The queue grows lazily; nothing is pre-allocated. Push is non-blocking - a full queue drops the value and counts it. The handler is never called concurrently with itself.

func NewDispatcher added in v1.999.330

func NewDispatcher[T any](limit int, handle func(T)) *Dispatcher[T]

NewDispatcher builds a dispatcher whose worker passes every pushed value to handle. limit bounds the queue length; a non-positive limit uses defaultDispatcherLimit. The queue is always bounded, so a stalled handler makes Push drop rather than grow memory unbounded.

func (*Dispatcher[T]) Dropped added in v1.999.330

func (d *Dispatcher[T]) Dropped() uint64

Dropped returns how many values have been dropped so far because the queue was full.

func (*Dispatcher[T]) Push added in v1.999.330

func (d *Dispatcher[T]) Push(v T) bool

Push hands a value to the worker without blocking and reports whether it was queued. A full queue or a stopped dispatcher drops the value, counts it, and returns false, so a producer that cares can back off, retry or surface an error instead of losing it silently.

func (*Dispatcher[T]) Stop added in v1.999.330

func (d *Dispatcher[T]) Stop() []T

Stop prevents further work, waits for any in-flight handler to finish, and returns the values still queued so the caller can flush, inspect or discard them instead of losing them silently. After Stop returns the handler is guaranteed not to be running. Best-effort: a Push that raced Stop may or may not be included. Idempotent; a later Stop returns nil.

type Flusher added in v1.999.330

type Flusher interface {
	io.Writer
	Reset(io.Writer)
	Stop()
}

func NewFlusher

func NewFlusher(w io.Writer) Flusher

func NewFlusherWithKeepAlive

func NewFlusherWithKeepAlive(w io.Writer, keepalive []byte, keepalivePeriod time.Duration) Flusher

type ItemMPSC

type ItemMPSC interface {
	Next() ItemMPSC
	Value() any
	Clear()
}

type Map

type Map[K comparable, V any] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K)

func (*Map[K, V]) DeleteNoLock

func (m *Map[K, V]) DeleteNoLock(key K)

DeleteNoLock to be used within RangeLock method

func (*Map[K, V]) Len

func (m *Map[K, V]) Len() int

func (*Map[K, V]) Load

func (m *Map[K, V]) Load(key K) (V, bool)

func (*Map[K, V]) LoadAndDelete

func (m *Map[K, V]) LoadAndDelete(key K) (V, bool)

func (*Map[K, V]) LoadOrStore

func (m *Map[K, V]) LoadOrStore(key K, value V) (V, bool)

func (*Map[K, V]) Range

func (m *Map[K, V]) Range(f func(k K, v V) bool)

func (*Map[K, V]) RangeLock

func (m *Map[K, V]) RangeLock(f func(k K, v V) bool)

RangeLock locks map during iterating. You can use DeleteNoLock/StoreNoLock within your f-function

func (*Map[K, V]) Store

func (m *Map[K, V]) Store(key K, value V)

type QueueMPSC

type QueueMPSC interface {
	Push(value any) bool
	Pop() (any, bool)
	Item() ItemMPSC
	// Len returns the number of items in the queue
	Len() int64
	// Size returns the limit for the queue. -1 - for unlimited
	Size() int64
	// Latency returns how long the oldest item has been in the queue (nanoseconds).
	// Safe to call from any goroutine.
	// Returns -1 if built without -tags=latency (measurement disabled).
	// Returns 0 if the queue is empty.
	Latency() int64

	Lock() bool
	Unlock() bool
}

func NewQueueLimitMPSC

func NewQueueLimitMPSC(limit int64) QueueMPSC

NewQueueLimitMPSC creates an MPSC queue bounded to the given length: Push returns false once the queue already holds limit items. A limit below 1 returns an unbounded queue (NewQueueMPSC).

func NewQueueMPSC

func NewQueueMPSC() QueueMPSC

type RuntimeMetrics added in v1.999.330

type RuntimeMetrics struct {
	// MemoryTotal is the total memory obtained from the OS, in bytes.
	MemoryTotal uint64

	// MemoryObjects is the memory occupied by live heap objects, in bytes.
	MemoryObjects uint64

	// MemoryLimit is the soft memory limit set via GOMEMLIMIT, in bytes.
	// MaxInt64 means no limit is set.
	MemoryLimit uint64

	// HeapLive is the heap memory occupied as of the last garbage collection, in bytes.
	HeapLive uint64

	// HeapGoal is the heap size that triggers the next garbage collection, in bytes.
	HeapGoal uint64

	// Goroutines is the current number of goroutines.
	Goroutines int64

	// GCCycles is the cumulative number of completed garbage collection cycles.
	GCCycles uint64

	// HeapAllocObjects is the cumulative number of heap objects allocated.
	HeapAllocObjects uint64

	// HeapFreeObjects is the cumulative number of heap objects freed. The difference
	// with HeapAllocObjects is the number of objects currently alive.
	HeapFreeObjects uint64

	// GCCPUFraction is the share of total CPU time spent in garbage collection.
	GCCPUFraction float64

	// CPUTimeGC is the cumulative CPU time spent in garbage collection, in seconds.
	CPUTimeGC float64

	// CPUTimeTotal is the cumulative CPU time available to the process, in seconds,
	// as defined by GOMAXPROCS. Includes idle time.
	CPUTimeTotal float64
}

RuntimeMetrics contains the runtime counters sampled through runtime/metrics. A metric unknown to the running Go version leaves its field zero.

func ReadRuntimeMetrics added in v1.999.330

func ReadRuntimeMetrics() RuntimeMetrics

ReadRuntimeMetrics samples the runtime counters. Unlike runtime.ReadMemStats it does not stop the world.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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