utils

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrScheduleTimeout = fmt.Errorf("schedule error: timed out")

ErrScheduleTimeout returned by Pool to indicate that there no free goroutines during some period of time.

Functions

func IsTTY

func IsTTY() bool

IsTTY returns true if program is running with TTY

func Keys added in v1.3.0

func Keys[T any](val map[string]T) []string

func NextRetry added in v1.4.7

func NextRetry(step int) time.Duration

NextRetry returns a cooldown duration before next attempt using a simple exponential backoff

func OpenFileLimit added in v0.6.3

func OpenFileLimit() (limitStr string)

OpenFileLimit returns a string displaying the current open file limit for the process or unknown if it's not possible to detect it

func ToJSON added in v1.2.2

func ToJSON[T any](val T) []byte

Types

type GoPool added in v1.1.0

type GoPool struct {
	// contains filtered or unexported fields
}

GoPool contains logic of goroutine reuse. Copied from https://github.com/gobwas/ws-examples/blob/master/src/gopool/pool.go

func AllPools added in v1.1.0

func AllPools() []*GoPool

Return all active pools

func NewGoPool added in v1.1.0

func NewGoPool(name string, size int) *GoPool

NewGoPool creates new goroutine pool with given size. Start size defaults to 20% of the max size but not greater than 1024. Queue size defaults to 50% of the max size.

func (*GoPool) Name added in v1.1.0

func (p *GoPool) Name() string

func (*GoPool) Schedule added in v1.1.0

func (p *GoPool) Schedule(task func())

Schedule schedules task to be executed over pool's workers.

func (*GoPool) ScheduleTimeout added in v1.1.0

func (p *GoPool) ScheduleTimeout(timeout time.Duration, task func()) error

ScheduleTimeout schedules task to be executed over pool's workers. It returns ErrScheduleTimeout when no free workers met during given timeout.

func (*GoPool) Size added in v1.1.0

func (p *GoPool) Size() int

type GracefulSignals added in v1.4.2

type GracefulSignals struct {
	// contains filtered or unexported fields
}

The struct implementing logic for graceful shutdown in response to OS signals.

func NewGracefulSignals added in v1.4.2

func NewGracefulSignals(timeout time.Duration) *GracefulSignals

Create new GracefulSignals struct.

func (*GracefulSignals) Handle added in v1.4.2

func (s *GracefulSignals) Handle(handler signalHandler)

func (*GracefulSignals) HandleForceTerminate added in v1.4.2

func (s *GracefulSignals) HandleForceTerminate(handler func())

func (*GracefulSignals) Listen added in v1.4.2

func (s *GracefulSignals) Listen()

type MessageVerifier added in v1.2.0

type MessageVerifier struct {
	// contains filtered or unexported fields
}

func NewMessageVerifier added in v1.2.0

func NewMessageVerifier(key string) *MessageVerifier

func (*MessageVerifier) Generate added in v1.4.0

func (m *MessageVerifier) Generate(payload interface{}) (string, error)

func (*MessageVerifier) Sign added in v1.5.0

func (m *MessageVerifier) Sign(payload []byte) ([]byte, error)

func (*MessageVerifier) Verified added in v1.2.0

func (m *MessageVerifier) Verified(msg string) (interface{}, error)

func (*MessageVerifier) VerifySignature added in v1.5.0

func (m *MessageVerifier) VerifySignature(payload []byte, digest []byte) bool

type PriorityQueue added in v1.4.0

type PriorityQueue[T any, P constraints.Ordered] []*PriorityQueueItem[T, P]

func NewPriorityQueue added in v1.4.0

func NewPriorityQueue[T any, P constraints.Ordered]() *PriorityQueue[T, P]

func (PriorityQueue[T, P]) Len added in v1.4.0

func (pq PriorityQueue[T, P]) Len() int

func (PriorityQueue[T, P]) Less added in v1.4.0

func (pq PriorityQueue[T, P]) Less(i, j int) bool

func (*PriorityQueue[T, P]) Peek added in v1.4.0

func (pq *PriorityQueue[T, P]) Peek() *PriorityQueueItem[T, P]

func (*PriorityQueue[T, P]) Pop added in v1.4.0

func (pq *PriorityQueue[T, P]) Pop() any

func (*PriorityQueue[T, P]) PopItem added in v1.4.0

func (pq *PriorityQueue[T, P]) PopItem() *PriorityQueueItem[T, P]

func (*PriorityQueue[T, P]) Push added in v1.4.0

func (pq *PriorityQueue[T, P]) Push(x any)

func (*PriorityQueue[T, P]) PushItem added in v1.4.0

func (pq *PriorityQueue[T, P]) PushItem(v T, priority P) *PriorityQueueItem[T, P]

func (*PriorityQueue[T, P]) Remove added in v1.4.0

func (pq *PriorityQueue[T, P]) Remove(item *PriorityQueueItem[T, P])

func (PriorityQueue[T, P]) Swap added in v1.4.0

func (pq PriorityQueue[T, P]) Swap(i, j int)

func (*PriorityQueue[T, P]) Update added in v1.4.0

func (pq *PriorityQueue[T, P]) Update(item *PriorityQueueItem[T, P], priority P)

Update modifies the priority and value of an Item in the queue.

type PriorityQueueItem added in v1.4.0

type PriorityQueueItem[T any, P constraints.Ordered] struct {
	// contains filtered or unexported fields
}

An PriorityQueueItem is something we manage in a priority queue.

func (PriorityQueueItem[T, P]) Priority added in v1.4.0

func (pq PriorityQueueItem[T, P]) Priority() P

func (PriorityQueueItem[T, P]) Value added in v1.4.0

func (pq PriorityQueueItem[T, P]) Value() T

Jump to

Keyboard shortcuts

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