Documentation
¶
Index ¶
- Variables
- func IsTTY() bool
- func Keys[T any](val map[string]T) []string
- func NextRetry(step int) time.Duration
- func OpenFileLimit() (limitStr string)
- func ToJSON[T any](val T) []byte
- type GoPool
- type GracefulSignals
- type MessageVerifier
- func (m *MessageVerifier) Generate(payload interface{}) (string, error)
- func (m *MessageVerifier) Sign(payload []byte) ([]byte, error)
- func (m *MessageVerifier) Validate(msg string) error
- func (m *MessageVerifier) Verified(msg string) (interface{}, error)
- func (m *MessageVerifier) VerifySignature(payload []byte, digest []byte) bool
- type PriorityQueue
- func (pq PriorityQueue[T, P]) Len() int
- func (pq PriorityQueue[T, P]) Less(i, j int) bool
- func (pq *PriorityQueue[T, P]) Peek() *PriorityQueueItem[T, P]
- func (pq *PriorityQueue[T, P]) Pop() any
- func (pq *PriorityQueue[T, P]) PopItem() *PriorityQueueItem[T, P]
- func (pq *PriorityQueue[T, P]) Push(x any)
- func (pq *PriorityQueue[T, P]) PushItem(v T, priority P) *PriorityQueueItem[T, P]
- func (pq *PriorityQueue[T, P]) Remove(item *PriorityQueueItem[T, P])
- func (pq PriorityQueue[T, P]) Swap(i, j int)
- func (pq *PriorityQueue[T, P]) Update(item *PriorityQueueItem[T, P], priority P)
- type PriorityQueueItem
Constants ¶
This section is empty.
Variables ¶
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 NextRetry ¶
NextRetry returns a cooldown duration before next attempt using a simple exponential backoff
func OpenFileLimit ¶
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
Types ¶
type GoPool ¶
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 NewGoPool ¶
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) Schedule ¶
func (p *GoPool) Schedule(task func())
Schedule schedules task to be executed over pool's workers.
func (*GoPool) ScheduleTimeout ¶
ScheduleTimeout schedules task to be executed over pool's workers. It returns ErrScheduleTimeout when no free workers met during given timeout.
type GracefulSignals ¶
type GracefulSignals struct {
// contains filtered or unexported fields
}
The struct implementing logic for graceful shutdown in response to OS signals.
func NewGracefulSignals ¶
func NewGracefulSignals(timeout time.Duration) *GracefulSignals
Create new GracefulSignals struct.
func (*GracefulSignals) Handle ¶
func (s *GracefulSignals) Handle(handler signalHandler)
func (*GracefulSignals) HandleForceTerminate ¶
func (s *GracefulSignals) HandleForceTerminate(handler func())
func (*GracefulSignals) Listen ¶
func (s *GracefulSignals) Listen()
type MessageVerifier ¶
type MessageVerifier struct {
// contains filtered or unexported fields
}
func NewMessageVerifier ¶
func NewMessageVerifier(key string) *MessageVerifier
func (*MessageVerifier) Generate ¶
func (m *MessageVerifier) Generate(payload interface{}) (string, error)
func (*MessageVerifier) Validate ¶
func (m *MessageVerifier) Validate(msg string) error
func (*MessageVerifier) Verified ¶
func (m *MessageVerifier) Verified(msg string) (interface{}, error)
func (*MessageVerifier) VerifySignature ¶
func (m *MessageVerifier) VerifySignature(payload []byte, digest []byte) bool
type PriorityQueue ¶
type PriorityQueue[T any, P constraints.Ordered] []*PriorityQueueItem[T, P]
func NewPriorityQueue ¶
func NewPriorityQueue[T any, P constraints.Ordered]() *PriorityQueue[T, P]
func (PriorityQueue[T, P]) Len ¶
func (pq PriorityQueue[T, P]) Len() int
func (PriorityQueue[T, P]) Less ¶
func (pq PriorityQueue[T, P]) Less(i, j int) bool
func (*PriorityQueue[T, P]) Peek ¶
func (pq *PriorityQueue[T, P]) Peek() *PriorityQueueItem[T, P]
func (*PriorityQueue[T, P]) Pop ¶
func (pq *PriorityQueue[T, P]) Pop() any
func (*PriorityQueue[T, P]) PopItem ¶
func (pq *PriorityQueue[T, P]) PopItem() *PriorityQueueItem[T, P]
func (*PriorityQueue[T, P]) Push ¶
func (pq *PriorityQueue[T, P]) Push(x any)
func (*PriorityQueue[T, P]) PushItem ¶
func (pq *PriorityQueue[T, P]) PushItem(v T, priority P) *PriorityQueueItem[T, P]
func (*PriorityQueue[T, P]) Remove ¶
func (pq *PriorityQueue[T, P]) Remove(item *PriorityQueueItem[T, P])
func (PriorityQueue[T, P]) Swap ¶
func (pq PriorityQueue[T, P]) Swap(i, j int)
func (*PriorityQueue[T, P]) Update ¶
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 ¶
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 ¶
func (pq PriorityQueueItem[T, P]) Priority() P
func (PriorityQueueItem[T, P]) Value ¶
func (pq PriorityQueueItem[T, P]) Value() T