utils

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: MIT Imports: 16 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Chars = [...]string{
	log.DebugLevel: "D",
	log.InfoLevel:  "I",
	log.WarnLevel:  "W",
	log.ErrorLevel: "E",
	log.FatalLevel: "F",
}

Chars mapping.

View Source
var Colors = [...]int{
	log.DebugLevel: gray,
	log.InfoLevel:  blue,
	log.WarnLevel:  yellow,
	log.ErrorLevel: red,
	log.FatalLevel: red,
}

Colors mapping.

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.

View Source
var Strings = [...]string{
	log.DebugLevel: "DEBUG",
	log.InfoLevel:  "INFO",
	log.WarnLevel:  "WARN",
	log.ErrorLevel: "ERROR",
	log.FatalLevel: "FATAL",
}

Strings mapping.

Functions

func InitLogger

func InitLogger(format string, level string) error

InitLogger sets log level, format and output

func IsTTY

func IsTTY() bool

IsTTY returns true if program is running with TTY

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 LogHandler

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

LogHandler with TTY awareness

func (*LogHandler) HandleLog

func (h *LogHandler) HandleLog(e *log.Entry) error

HandleLog is a method called by logger to record a log entry

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) Verified added in v1.2.0

func (m *MessageVerifier) Verified(msg string) (string, error)

Jump to

Keyboard shortcuts

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