astikit

package module
v0.47.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: MIT Imports: 27 Imported by: 193

README

GoReportCard GoDoc Test Coveralls

astikit is a set of golang helpers that don't require any external dependencies.

Documentation

Index

Constants

View Source
const (
	ExecStatusCrashed = "crashed"
	ExecStatusRunning = "running"
	ExecStatusStopped = "stopped"
)

Statuses

View Source
const (
	IpcFlagCreat = int(C.IPC_CREAT)
	IpcFlagExcl  = int(C.IPC_EXCL)
)
View Source
const (
	// Calling Add() only blocks if the chan has been started and the ctx
	// has not been canceled
	ChanAddStrategyBlockWhenStarted = "block.when.started"
	// Calling Add() never blocks
	ChanAddStrategyNoBlock = "no.block"
	ChanOrderFIFO          = "fifo"
	ChanOrderFILO          = "filo"
)

Chan constants

View Source
const (
	StatNameWorkRatio = "astikit.work.ratio"
)

Stat names

Variables

View Source
var (
	DefaultDirMode os.FileMode = 0755
)

Default modes

View Source
var ErrHTTPSenderUnmarshaledError = errors.New("astikit: unmarshaled error")

Functions

func BoolPtr added in v0.0.3

func BoolPtr(i bool) *bool

BoolPtr transforms a bool into a *bool

func BoolToUInt32 added in v0.31.0

func BoolToUInt32(b bool) uint32

func ByteHamming84Decode added in v0.0.10

func ByteHamming84Decode(i uint8) (o uint8, ok bool)

ByteHamming84Decode hamming 8/4 decodes

func ByteParity added in v0.0.10

func ByteParity(i uint8) (o uint8, ok bool)

ByteParity returns the byte parity

func BytePtr added in v0.0.3

func BytePtr(i byte) *byte

BytePtr transforms a byte into a *byte

func BytesPad added in v0.0.10

func BytesPad(i []byte, repeat byte, length int, options ...PadOption) []byte

BytesPad pads the slice of bytes with additionnal options

func ChainHTTPMiddlewares added in v0.0.3

func ChainHTTPMiddlewares(h http.Handler, ms ...HTTPMiddleware) http.Handler

ChainHTTPMiddlewares chains HTTP middlewares

func ChainHTTPMiddlewaresWithPrefix added in v0.0.3

func ChainHTTPMiddlewaresWithPrefix(h http.Handler, prefixes []string, ms ...HTTPMiddleware) http.Handler

ChainHTTPMiddlewaresWithPrefix chains HTTP middlewares if one of prefixes is present

func ConvertPCMBitDepth added in v0.0.3

func ConvertPCMBitDepth(srcSample int, srcBitDepth, dstBitDepth int) (dstSample int, err error)

ConvertPCMBitDepth converts the PCM bit depth

func Copy added in v0.0.5

func Copy(ctx context.Context, dst io.Writer, src io.Reader) (int64, error)

Copy is a copy with a context

func CopyFile added in v0.0.5

func CopyFile(ctx context.Context, dst, src string, f CopyFileFunc) (err error)

CopyFile is a cancellable copy of a local file to a local or remote location

func DurationPtr added in v0.0.3

func DurationPtr(i time.Duration) *time.Duration

DurationPtr transforms a time.Duration into a *time.Duration

func ErrorCause added in v0.2.0

func ErrorCause(err error) error

ErrorCause returns the cause of an error

func FlagCmd added in v0.0.4

func FlagCmd() (o string)

FlagCmd retrieves the command from the input Args

func Float64Ptr added in v0.0.3

func Float64Ptr(i float64) *float64

Float64Ptr transforms a float64 into a *float64

func HTTPSenderDefaultStatusCodeFunc added in v0.29.0

func HTTPSenderDefaultStatusCodeFunc(code int) error

func Int64Ptr added in v0.0.3

func Int64Ptr(i int64) *int64

Int64Ptr transforms an int64 into an *int64

func IntPtr added in v0.0.3

func IntPtr(i int) *int

IntPtr transforms an int into an *int

func JSONClone added in v0.22.0

func JSONClone(src, dst interface{}) (err error)

func JSONEqual added in v0.22.0

func JSONEqual(a, b interface{}) bool

func LocalCopyFileFunc added in v0.0.5

func LocalCopyFileFunc(ctx context.Context, dst string, srcStat os.FileInfo, srcFile *os.File) (err error)

LocalCopyFileFunc is the local CopyFileFunc that allows doing cross partition copies

func MoveFile added in v0.0.8

func MoveFile(ctx context.Context, dst, src string, f CopyFileFunc) (err error)

MoveFile is a cancellable move of a local file to a local or remote location

func NopCloser added in v0.0.5

func NopCloser(w io.Writer) io.WriteCloser

NopCloser returns a WriteCloser with a no-op Close method wrapping the provided Writer w.

func PCMNormalize added in v0.0.3

func PCMNormalize(samples []int, bitDepth int) (o []int)

PCMNormalize normalizes the PCM samples

func PadCut added in v0.0.10

func PadCut(p *bytesPadder)

PadCut is a PadOption It indicates to the padder it must cut the input to the provided length if its original length is bigger

func PadLeft added in v0.0.10

func PadLeft(p *bytesPadder)

PadLeft is a PadOption It indicates additionnal bytes have to be added to the left

func PadRight added in v0.0.10

func PadRight(p *bytesPadder)

PadRight is a PadOption It indicates additionnal bytes have to be added to the right

func RandStr added in v0.0.5

func RandStr(n int) string

RandStr generates a random string of length n https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-golang

func ServeHTTP added in v0.0.2

func ServeHTTP(w *Worker, o ServeHTTPOptions)

ServeHTTP spawns an HTTP server

func Sleep

func Sleep(ctx context.Context, d time.Duration) (err error)

Sleep is a cancellable sleep

func SortInt64 added in v0.0.6

func SortInt64(a []int64)

SortInt64 sorts a slice of int64s in increasing order.

func SortUint64 added in v0.42.0

func SortUint64(a []uint64)

SortUint64 sorts a slice of uint64s in increasing order.

func StrPad added in v0.0.10

func StrPad(i string, repeat rune, length int, options ...PadOption) string

StrPad pads the string with additionnal options

func StrPtr added in v0.0.3

func StrPtr(i string) *string

StrPtr transforms a string into a *string

func StrSlicePtr added in v0.14.0

func StrSlicePtr(i []string) *[]string

StrSlicePtr transforms a []string into a *[]string

func TimePtr added in v0.18.0

func TimePtr(i time.Time) *time.Time

TimePtr transforms a time.Time into a *time.Time

func UInt16Ptr added in v0.39.0

func UInt16Ptr(i uint16) *uint16

UInt16Ptr transforms a uint16 into a *uint16

func UInt32Ptr added in v0.0.3

func UInt32Ptr(i uint32) *uint32

UInt32Ptr transforms a uint32 into a *uint32

func UInt64Ptr added in v0.36.0

func UInt64Ptr(i uint64) *uint64

UInt64Ptr transforms a uint64 into a *uint64

func UInt8Ptr added in v0.0.3

func UInt8Ptr(i uint8) *uint8

UInt8Ptr transforms a uint8 into a *uint8

func Unzip added in v0.0.7

func Unzip(ctx context.Context, dst, src string) (err error)

Unzip unzips a src into a dst Possible src formats are:

  • /path/to/zip.zip
  • /path/to/zip.zip/root/path

func Zip added in v0.0.7

func Zip(ctx context.Context, dst, src string) (err error)

Zip zips a src into a dst Possible dst formats are:

  • /path/to/zip.zip
  • /path/to/zip.zip/root/path

Types

type AtomicDuration added in v0.37.0

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

func NewAtomicDuration added in v0.37.0

func NewAtomicDuration(d time.Duration) *AtomicDuration

func (*AtomicDuration) Add added in v0.37.0

func (d *AtomicDuration) Add(delta time.Duration)

func (*AtomicDuration) Duration added in v0.37.0

func (d *AtomicDuration) Duration() time.Duration

type AtomicDurationAvgStat added in v0.37.0

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

func NewAtomicDurationAvgStat added in v0.37.0

func NewAtomicDurationAvgStat(d *AtomicDuration, count *uint64) *AtomicDurationAvgStat

func (*AtomicDurationAvgStat) Value added in v0.37.0

func (s *AtomicDurationAvgStat) Value(_ time.Duration) interface{}

type AtomicDurationPercentageStat added in v0.37.0

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

func NewAtomicDurationPercentageStat added in v0.37.0

func NewAtomicDurationPercentageStat(d *AtomicDuration) *AtomicDurationPercentageStat

func (*AtomicDurationPercentageStat) Value added in v0.37.0

func (s *AtomicDurationPercentageStat) Value(d time.Duration) interface{}

type AtomicUint64RateStat added in v0.37.0

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

func NewAtomicUint64RateStat added in v0.37.0

func NewAtomicUint64RateStat(v *uint64) *AtomicUint64RateStat

func (*AtomicUint64RateStat) Value added in v0.37.0

func (s *AtomicUint64RateStat) Value(d time.Duration) interface{}

type BiMap added in v0.0.10

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

BiMap represents a bidirectional map

func NewBiMap added in v0.0.10

func NewBiMap() *BiMap

NewBiMap creates a new BiMap

func (*BiMap) Get added in v0.0.10

func (m *BiMap) Get(k interface{}) (interface{}, bool)

Get gets the value in the forward map based on the provided key

func (*BiMap) GetInverse added in v0.0.10

func (m *BiMap) GetInverse(k interface{}) (interface{}, bool)

GetInverse gets the value in the inverse map based on the provided key

func (*BiMap) MustGet added in v0.9.2

func (m *BiMap) MustGet(k interface{}) interface{}

MustGet gets the value in the forward map based on the provided key and panics if key is not found

func (*BiMap) MustGetInverse added in v0.9.2

func (m *BiMap) MustGetInverse(k interface{}) interface{}

MustGetInverse gets the value in the inverse map based on the provided key and panics if key is not found

func (*BiMap) Set added in v0.0.10

func (m *BiMap) Set(k, v interface{}) *BiMap

Set sets the value in the forward and inverse map for the provided forward key

func (*BiMap) SetInverse added in v0.0.10

func (m *BiMap) SetInverse(k, v interface{}) *BiMap

SetInverse sets the value in the forward and inverse map for the provided inverse key

type BitFlags added in v0.42.0

type BitFlags uint64

func (BitFlags) Add added in v0.42.0

func (fs BitFlags) Add(f uint64) uint64

func (BitFlags) Del added in v0.42.0

func (fs BitFlags) Del(f uint64) uint64

func (BitFlags) Has added in v0.42.0

func (fs BitFlags) Has(f uint64) bool

type BitsWriter added in v0.0.9

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

BitsWriter represents an object that can write individual bits into a writer in a developer-friendly way. Check out the Write method for more information. This is particularly helpful when you want to build a slice of bytes based on individual bits for testing purposes.

func NewBitsWriter added in v0.0.9

func NewBitsWriter(o BitsWriterOptions) (w *BitsWriter)

NewBitsWriter creates a new BitsWriter

func (*BitsWriter) SetWriteCallback added in v0.18.0

func (w *BitsWriter) SetWriteCallback(cb BitsWriterWriteCallback)

func (*BitsWriter) Write added in v0.0.9

func (w *BitsWriter) Write(i interface{}) error

Write writes bits into the writer. Bits are only written when there are enough to create a byte. When using a string or a bool, bits are added from left to right as if Available types are:

  • string("10010"): processed as n bits, n being the length of the input
  • []byte: processed as n bytes, n being the length of the input
  • bool: processed as one bit
  • uint8/uint16/uint32/uint64: processed as n bits, if type is uintn

func (*BitsWriter) WriteBytesN added in v0.19.0

func (w *BitsWriter) WriteBytesN(bs []byte, n int, padByte uint8) error

Writes exactly n bytes from bs Writes first n bytes of bs if len(bs) > n Pads with padByte at the end if len(bs) < n

func (*BitsWriter) WriteN added in v0.0.9

func (w *BitsWriter) WriteN(i interface{}, n int) error

WriteN writes the input into n bits

type BitsWriterBatch added in v0.17.0

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

BitsWriterBatch allows to chain multiple Write* calls and check for error only once For more info see https://github.com/asticode/go-astikit/pull/6

func NewBitsWriterBatch added in v0.17.0

func NewBitsWriterBatch(w *BitsWriter) BitsWriterBatch

func (*BitsWriterBatch) Err added in v0.17.0

func (b *BitsWriterBatch) Err() error

Returns first write error

func (*BitsWriterBatch) Write added in v0.17.0

func (b *BitsWriterBatch) Write(i interface{})

Calls BitsWriter.Write if there was no write error before

func (*BitsWriterBatch) WriteBytesN added in v0.19.0

func (b *BitsWriterBatch) WriteBytesN(bs []byte, n int, padByte uint8)

Calls BitsWriter.WriteBytesN if there was no write error before

func (*BitsWriterBatch) WriteN added in v0.17.0

func (b *BitsWriterBatch) WriteN(i interface{}, n int)

Calls BitsWriter.WriteN if there was no write error before

type BitsWriterOptions added in v0.0.9

type BitsWriterOptions struct {
	ByteOrder binary.ByteOrder
	// WriteCallback is called every time when full byte is written
	WriteCallback BitsWriterWriteCallback
	Writer        io.Writer
}

BitsWriterOptions represents BitsWriter options

type BitsWriterWriteCallback added in v0.18.0

type BitsWriterWriteCallback func([]byte)

type BufferPool added in v0.0.6

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

BufferPool represents a *bytes.Buffer pool

func NewBufferPool added in v0.0.6

func NewBufferPool() *BufferPool

NewBufferPool creates a new BufferPool

func (*BufferPool) New added in v0.0.6

func (p *BufferPool) New() *BufferPoolItem

New creates a new BufferPoolItem

type BufferPoolItem added in v0.0.6

type BufferPoolItem struct {
	*bytes.Buffer
	// contains filtered or unexported fields
}

BufferPoolItem represents a BufferPool item

func (*BufferPoolItem) Close added in v0.0.6

func (i *BufferPoolItem) Close() error

Close implements the io.Closer interface

type BytesIterator added in v0.0.9

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

BytesIterator represents an object capable of iterating sequentially and safely through a slice of bytes. This is particularly useful when you need to iterate through a slice of bytes and don't want to check for "index out of range" errors manually.

func NewBytesIterator added in v0.0.9

func NewBytesIterator(bs []byte) *BytesIterator

NewBytesIterator creates a new BytesIterator

func (*BytesIterator) Dump added in v0.0.9

func (i *BytesIterator) Dump() (bs []byte)

Dump dumps the rest of the slice

func (*BytesIterator) HasBytesLeft added in v0.0.9

func (i *BytesIterator) HasBytesLeft() bool

HasBytesLeft checks whether there are bytes left

func (*BytesIterator) Len added in v0.0.9

func (i *BytesIterator) Len() int

Len returns the slice length

func (*BytesIterator) NextByte added in v0.0.9

func (i *BytesIterator) NextByte() (b byte, err error)

NextByte returns the next byte

func (*BytesIterator) NextBytes added in v0.0.9

func (i *BytesIterator) NextBytes(n int) (bs []byte, err error)

NextBytes returns the n next bytes

func (*BytesIterator) NextBytesNoCopy added in v0.20.0

func (i *BytesIterator) NextBytesNoCopy(n int) (bs []byte, err error)

NextBytesNoCopy returns the n next bytes Be careful with this function as it doesn't make a copy of returned data. bs will point to internal BytesIterator buffer. If you need to modify returned bytes or store it for some time, use NextBytes instead

func (*BytesIterator) Offset added in v0.0.9

func (i *BytesIterator) Offset() int

Offset returns the offset

func (*BytesIterator) Seek added in v0.0.9

func (i *BytesIterator) Seek(n int)

Seek seeks to the nth byte

func (*BytesIterator) Skip added in v0.0.9

func (i *BytesIterator) Skip(n int)

Skip skips the n previous/next bytes

type Chan added in v0.0.3

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

Chan is an object capable of executing funcs in a specific order while controlling the conditions in which adding new funcs is blocking Check out ChanOptions for detailed options

func NewChan added in v0.0.3

func NewChan(o ChanOptions) *Chan

NewChan creates a new Chan

func (*Chan) Add added in v0.0.3

func (c *Chan) Add(i func())

Add adds a new item to the chan

func (*Chan) Reset added in v0.0.3

func (c *Chan) Reset()

Reset resets the chan

func (*Chan) Start added in v0.0.3

func (c *Chan) Start(ctx context.Context)

Start starts the chan by looping through functions in the buffer and executing them if any, or waiting for a new one otherwise

func (*Chan) StatOptions added in v0.37.0

func (c *Chan) StatOptions() []StatOptions

StatOptions returns the chan stat options

func (*Chan) Stats added in v0.13.0

func (c *Chan) Stats() ChanStats

Stats returns the chan stats

func (*Chan) Stop added in v0.0.3

func (c *Chan) Stop()

Stop stops the chan

type ChanOptions added in v0.0.3

type ChanOptions struct {
	// Determines the conditions in which Add() blocks. See constants with pattern ChanAddStrategy*
	// Default is ChanAddStrategyNoBlock
	AddStrategy string
	// Order in which the funcs will be processed. See constants with pattern ChanOrder*
	// Default is ChanOrderFIFO
	Order string
	// By default the funcs not yet processed when the context is cancelled are dropped.
	// If "ProcessAll" is true,  ALL funcs are processed even after the context is cancelled.
	// However, no funcs can be added after the context is cancelled
	ProcessAll bool
}

ChanOptions are Chan options

type ChanStats added in v0.37.0

type ChanStats struct {
	WorkDuration time.Duration
}

ChanStats represents the chan stats

type CloseFunc added in v0.0.4

type CloseFunc func()

type CloseFuncWithError added in v0.28.2

type CloseFuncWithError func() error

type Closer added in v0.0.4

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

Closer is an object that can close several things

func NewCloser added in v0.0.4

func NewCloser() *Closer

NewCloser creates a new closer

func (*Closer) Add added in v0.0.4

func (c *Closer) Add(f CloseFunc)

func (*Closer) AddWithError added in v0.28.2

func (c *Closer) AddWithError(f CloseFuncWithError)

func (*Closer) Append added in v0.22.0

func (c *Closer) Append(dst *Closer)

func (*Closer) Close added in v0.0.4

func (c *Closer) Close() error

Close implements the io.Closer interface

func (*Closer) Do added in v0.21.0

func (c *Closer) Do(fn func())

Do executes a callback while ensuring :

  • closer hasn't been closed before
  • closer can't be closed in between

func (*Closer) IsClosed added in v0.23.0

func (c *Closer) IsClosed() bool

func (*Closer) NewChild added in v0.0.4

func (c *Closer) NewChild() (child *Closer)

NewChild creates a new child closer

func (*Closer) OnClosed added in v0.23.0

func (c *Closer) OnClosed(fn CloserOnClosed)

type CloserOnClosed added in v0.23.0

type CloserOnClosed func(err error)

type CompleteLogger added in v0.1.0

CompleteLogger represents a complete logger

func AdaptStdLogger added in v0.0.4

func AdaptStdLogger(i StdLogger) CompleteLogger

AdaptStdLogger transforms an StdLogger into a CompleteLogger if needed

func AdaptTestLogger added in v0.24.0

func AdaptTestLogger(i TestLogger) CompleteLogger

AdaptTestLogger transforms a TestLogger into a CompleteLogger if needed

type CopyFileFunc added in v0.0.5

type CopyFileFunc func(ctx context.Context, dst string, srcStat os.FileInfo, srcFile *os.File) error

CopyFileFunc represents a CopyFile func

func SSHCopyFileFunc added in v0.0.5

func SSHCopyFileFunc(fn SSHSessionFunc) CopyFileFunc

SSHCopyFileFunc is the SSH CopyFileFunc that allows doing SSH copies

type CtxReader added in v0.0.5

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

CtxReader represents a reader with a context

func NewCtxReader added in v0.0.5

func NewCtxReader(ctx context.Context, r io.Reader) *CtxReader

NewCtxReader creates a reader with a context

func (*CtxReader) Read added in v0.0.5

func (r *CtxReader) Read(p []byte) (n int, err error)

Read implements the io.Reader interface

type DebugMutex added in v0.38.0

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

DebugMutex represents a rwmutex capable of logging its actions to ease deadlock debugging

func NewDebugMutex added in v0.38.0

func NewDebugMutex(name string, l StdLogger, opts ...DebugMutexOpt) *DebugMutex

NewDebugMutex creates a new debug mutex

func (*DebugMutex) Lock added in v0.38.0

func (m *DebugMutex) Lock()

Lock write locks the mutex

func (*DebugMutex) RLock added in v0.38.0

func (m *DebugMutex) RLock()

RLock read locks the mutex

func (*DebugMutex) RUnlock added in v0.38.0

func (m *DebugMutex) RUnlock()

RUnlock read unlocks the mutex

func (*DebugMutex) Unlock added in v0.38.0

func (m *DebugMutex) Unlock()

Unlock write unlocks the mutex

type DebugMutexOpt added in v0.38.0

type DebugMutexOpt func(m *DebugMutex)

DebugMutexOpt represents a debug mutex option

func DebugMutexWithDeadlockDetection added in v0.38.0

func DebugMutexWithDeadlockDetection(timeout time.Duration) DebugMutexOpt

DebugMutexWithDeadlockDetection allows detecting deadlock for all mutex locks

func DebugMutexWithLockLogging added in v0.38.0

func DebugMutexWithLockLogging(ll LoggerLevel) DebugMutexOpt

DebugMutexWithLockLogging allows logging all mutex locks

type Errors added in v0.0.4

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

Errors is an error containing multiple errors

func NewErrors added in v0.0.4

func NewErrors(errs ...error) *Errors

NewErrors creates new errors

func (*Errors) Add added in v0.0.4

func (errs *Errors) Add(err error)

Add adds a new error

func (*Errors) Error added in v0.0.4

func (errs *Errors) Error() string

Error implements the error interface

func (*Errors) Is added in v0.40.0

func (errs *Errors) Is(target error) bool

func (*Errors) IsNil added in v0.0.4

func (errs *Errors) IsNil() bool

IsNil checks whether the error is nil

func (*Errors) Loop added in v0.0.4

func (errs *Errors) Loop(fn func(idx int, err error) bool)

Loop loops through the errors

type EventHandler added in v0.41.0

type EventHandler func(payload interface{}) (delete bool)

type EventManager added in v0.41.0

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

func NewEventManager added in v0.41.0

func NewEventManager() *EventManager

func (*EventManager) Emit added in v0.41.0

func (m *EventManager) Emit(n EventName, payload interface{})

func (*EventManager) Off added in v0.42.0

func (m *EventManager) Off(id uint64)

func (*EventManager) On added in v0.41.0

type EventName added in v0.41.0

type EventName string

type Eventer added in v0.0.12

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

Eventer represents an object that can dispatch simple events (name + payload)

func NewEventer added in v0.0.12

func NewEventer(o EventerOptions) *Eventer

NewEventer creates a new eventer

func (*Eventer) Dispatch added in v0.0.12

func (e *Eventer) Dispatch(name string, payload interface{})

Dispatch dispatches a payload for a specific name

func (*Eventer) On added in v0.0.12

func (e *Eventer) On(name string, h EventerHandler)

On adds an handler for a specific name

func (*Eventer) Reset added in v0.0.12

func (e *Eventer) Reset()

Reset resets the eventer

func (*Eventer) Start added in v0.0.12

func (e *Eventer) Start(ctx context.Context)

Start starts the eventer. It is blocking

func (*Eventer) Stop added in v0.0.12

func (e *Eventer) Stop()

Stop stops the eventer

type EventerHandler added in v0.0.12

type EventerHandler func(payload interface{})

EventerHandler represents a function that can handle the payload of an event

type EventerOptions added in v0.0.12

type EventerOptions struct {
	Chan ChanOptions
}

EventerOptions represents Eventer options

type ExecCmdOptions added in v0.0.2

type ExecCmdOptions struct {
	Args       []string
	CmdAdapter func(cmd *exec.Cmd, h *ExecHandler) error
	Name       string
	StopFunc   func(cmd *exec.Cmd) error
}

ExecCmdOptions represents exec options

type ExecHandler added in v0.0.2

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

ExecHandler represents an object capable of handling the execution of a cmd

func ExecCmd added in v0.0.2

func ExecCmd(w *Worker, o ExecCmdOptions) (h *ExecHandler, err error)

ExecCmd executes a cmd The process will be stopped when the worker stops

func (*ExecHandler) Status added in v0.0.2

func (h *ExecHandler) Status() string

Status returns the cmd status

func (*ExecHandler) Stop added in v0.0.2

func (h *ExecHandler) Stop()

Stop stops the cmd

type FlagStrings added in v0.0.9

type FlagStrings struct {
	Map   map[string]bool
	Slice *[]string
}

FlagStrings represents a flag that can be set several times and stores unique string values

func NewFlagStrings added in v0.0.9

func NewFlagStrings() FlagStrings

NewFlagStrings creates a new FlagStrings

func (FlagStrings) Set added in v0.0.9

func (f FlagStrings) Set(i string) error

Set implements the flag.Value interface

func (FlagStrings) String added in v0.0.9

func (f FlagStrings) String() string

String implements the flag.Value interface

type GoroutineLimiter added in v0.0.6

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

GoroutineLimiter is an object capable of doing several things in parallel while maintaining the max number of things running in parallel under a threshold

func NewGoroutineLimiter added in v0.0.6

func NewGoroutineLimiter(o GoroutineLimiterOptions) (l *GoroutineLimiter)

NewGoroutineLimiter creates a new GoroutineLimiter

func (*GoroutineLimiter) Close added in v0.0.6

func (l *GoroutineLimiter) Close() error

Close closes the limiter properly

func (*GoroutineLimiter) Do added in v0.0.6

Do executes custom work in a goroutine

type GoroutineLimiterFunc added in v0.0.6

type GoroutineLimiterFunc func()

GoroutineLimiterFunc is a GoroutineLimiter func

type GoroutineLimiterOptions added in v0.0.6

type GoroutineLimiterOptions struct {
	Max int
}

GoroutineLimiterOptions represents GoroutineLimiter options

type HTTPClient added in v0.0.4

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient represents an HTTP client

type HTTPDownloader added in v0.0.6

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

HTTPDownloader represents an object capable of downloading several HTTP srcs simultaneously and doing stuff to the results

func NewHTTPDownloader added in v0.0.6

func NewHTTPDownloader(o HTTPDownloaderOptions) (d *HTTPDownloader)

NewHTTPDownloader creates a new HTTPDownloader

func (*HTTPDownloader) Close added in v0.0.6

func (d *HTTPDownloader) Close() error

Close closes the downloader properly

func (*HTTPDownloader) DownloadInDirectory added in v0.0.6

func (d *HTTPDownloader) DownloadInDirectory(ctx context.Context, dst string, srcs ...HTTPDownloaderSrc) error

DownloadInDirectory downloads in parallel a set of srcs and saves them in a dst directory

func (*HTTPDownloader) DownloadInFile added in v0.0.6

func (d *HTTPDownloader) DownloadInFile(ctx context.Context, dst string, srcs ...HTTPDownloaderSrc) (err error)

DownloadInFile downloads in parallel a set of srcs and concatenates them in a dst file while maintaining the initial order

func (*HTTPDownloader) DownloadInWriter added in v0.0.6

func (d *HTTPDownloader) DownloadInWriter(ctx context.Context, dst io.Writer, srcs ...HTTPDownloaderSrc) error

DownloadInWriter downloads in parallel a set of srcs and concatenates them in a writer while maintaining the initial order

type HTTPDownloaderOptions added in v0.0.6

type HTTPDownloaderOptions struct {
	Limiter      GoroutineLimiterOptions
	ResponseFunc HTTPResponseFunc
	Sender       HTTPSenderOptions
}

HTTPDownloaderOptions represents HTTPDownloader options

type HTTPDownloaderSrc added in v0.0.6

type HTTPDownloaderSrc struct {
	Body   io.Reader
	Header http.Header
	Method string
	URL    string
}

type HTTPMiddleware added in v0.0.3

type HTTPMiddleware func(http.Handler) http.Handler

HTTPMiddleware represents an HTTP middleware

func HTTPMiddlewareBasicAuth added in v0.0.3

func HTTPMiddlewareBasicAuth(username, password string) HTTPMiddleware

HTTPMiddlewareBasicAuth adds basic HTTP auth to an HTTP handler

func HTTPMiddlewareCORSHeaders added in v0.15.0

func HTTPMiddlewareCORSHeaders() HTTPMiddleware

HTTPMiddlewareCORSHeaders adds CORS headers to an HTTP handler

func HTTPMiddlewareContentType added in v0.0.3

func HTTPMiddlewareContentType(contentType string) HTTPMiddleware

HTTPMiddlewareContentType adds a content type to an HTTP handler

func HTTPMiddlewareHeaders added in v0.0.5

func HTTPMiddlewareHeaders(vs map[string]string) HTTPMiddleware

HTTPMiddlewareHeaders adds headers to an HTTP handler

type HTTPResponseFunc added in v0.0.6

type HTTPResponseFunc func(resp *http.Response) error

HTTPResponseFunc is a func that can process an $http.Response

type HTTPSendJSONOptions added in v0.9.2

type HTTPSendJSONOptions struct {
	BodyError      interface{}
	BodyIn         interface{}
	BodyOut        interface{}
	HeadersIn      map[string]string
	HeadersOut     HTTPSenderHeaderFunc
	Host           string
	Method         string
	StatusCodeFunc HTTPSenderStatusCodeFunc
	URL            string
}

HTTPSendJSONOptions represents SendJSON options

type HTTPSender added in v0.0.4

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

HTTPSender represents an object capable of sending http requests

func NewHTTPSender added in v0.0.4

func NewHTTPSender(o HTTPSenderOptions) (s *HTTPSender)

NewHTTPSender creates a new HTTP sender

func (*HTTPSender) Send added in v0.0.4

func (s *HTTPSender) Send(req *http.Request) (*http.Response, error)

Send sends a new *http.Request

func (*HTTPSender) SendJSON added in v0.9.2

func (s *HTTPSender) SendJSON(o HTTPSendJSONOptions) (err error)

SendJSON sends a new JSON HTTP request

func (*HTTPSender) SendWithTimeout added in v0.5.0

func (s *HTTPSender) SendWithTimeout(req *http.Request, timeout time.Duration) (resp *http.Response, err error)

SendWithTimeout sends a new *http.Request with a timeout

type HTTPSenderHeaderFunc added in v0.27.0

type HTTPSenderHeaderFunc func(h http.Header)

type HTTPSenderOptions added in v0.0.4

type HTTPSenderOptions struct {
	Client     HTTPClient
	Logger     StdLogger
	RetryFunc  HTTPSenderRetryFunc
	RetryMax   int
	RetrySleep time.Duration
	Timeout    time.Duration
}

HTTPSenderOptions represents HTTPSender options

type HTTPSenderRetryFunc added in v0.0.4

type HTTPSenderRetryFunc func(resp *http.Response) error

HTTPSenderRetryFunc is a function that decides whether to retry an HTTP request

type HTTPSenderStatusCodeFunc added in v0.29.1

type HTTPSenderStatusCodeFunc func(code int) error

type Limiter added in v0.0.3

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

Limiter represents a limiter

func NewLimiter added in v0.0.3

func NewLimiter() *Limiter

NewLimiter creates a new limiter

func (*Limiter) Add added in v0.0.3

func (l *Limiter) Add(name string, cap int, period time.Duration) *LimiterBucket

Add adds a new bucket

func (*Limiter) Bucket added in v0.0.3

func (l *Limiter) Bucket(name string) (b *LimiterBucket, ok bool)

Bucket retrieves a bucket from the limiter

func (*Limiter) Close added in v0.0.3

func (l *Limiter) Close()

Close closes the limiter properly

type LimiterBucket added in v0.0.3

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

LimiterBucket represents a limiter bucket

func (*LimiterBucket) Close added in v0.0.3

func (b *LimiterBucket) Close()

close closes the bucket properly

func (*LimiterBucket) Inc added in v0.0.3

func (b *LimiterBucket) Inc() bool

Inc increments the bucket count

type LoggerLevel added in v0.34.0

type LoggerLevel int

LoggerLevel represents a logger level

const (
	LoggerLevelDebug LoggerLevel = iota
	LoggerLevelInfo
	LoggerLevelWarn
	LoggerLevelError
	LoggerLevelFatal
)

Logger levels

func LoggerLevelFromString added in v0.34.0

func LoggerLevelFromString(s string) LoggerLevel

LoggerLevelFromString creates a logger level from string

func (LoggerLevel) MarshalText added in v0.34.0

func (l LoggerLevel) MarshalText() ([]byte, error)

func (LoggerLevel) String added in v0.34.0

func (l LoggerLevel) String() string

func (*LoggerLevel) UnmarshalText added in v0.34.0

func (l *LoggerLevel) UnmarshalText(b []byte) error

type PCMChannelsConverter added in v0.0.3

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

PCMChannelsConverter is an object of converting PCM's channels

func NewPCMChannelsConverter added in v0.0.3

func NewPCMChannelsConverter(srcNumChannels, dstNumChannels int, fn PCMSampleFunc) *PCMChannelsConverter

NewPCMChannelsConverter creates a new PCMChannelsConverter

func (*PCMChannelsConverter) Add added in v0.0.3

func (c *PCMChannelsConverter) Add(i int) (err error)

Add adds a new sample to the converter

func (*PCMChannelsConverter) Reset added in v0.0.3

func (c *PCMChannelsConverter) Reset()

Reset resets the converter

type PCMSampleFunc added in v0.0.3

type PCMSampleFunc func(s int) error

PCMSampleFunc is a func that can process a sample

type PCMSampleRateConverter added in v0.0.3

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

PCMSampleRateConverter is an object capable of converting a PCM's sample rate

func NewPCMSampleRateConverter added in v0.0.3

func NewPCMSampleRateConverter(srcSampleRate, dstSampleRate, numChannels int, fn PCMSampleFunc) *PCMSampleRateConverter

NewPCMSampleRateConverter creates a new PCMSampleRateConverter

func (*PCMSampleRateConverter) Add added in v0.0.3

func (c *PCMSampleRateConverter) Add(i int) (err error)

Add adds a new sample to the converter

func (*PCMSampleRateConverter) Reset added in v0.0.3

func (c *PCMSampleRateConverter) Reset()

Reset resets the converter

type PCMSilenceDetector added in v0.0.3

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

PCMSilenceDetector represents a PCM silence detector

func NewPCMSilenceDetector added in v0.0.3

func NewPCMSilenceDetector(o PCMSilenceDetectorOptions) (d *PCMSilenceDetector)

NewPCMSilenceDetector creates a new silence detector

func (*PCMSilenceDetector) Add added in v0.0.3

func (d *PCMSilenceDetector) Add(samples []int) (validSamples [][]int)

Add adds samples to the buffer and checks whether there are valid samples between silences

func (*PCMSilenceDetector) Reset added in v0.0.3

func (d *PCMSilenceDetector) Reset()

Reset resets the silence detector

type PCMSilenceDetectorOptions added in v0.0.3

type PCMSilenceDetectorOptions struct {
	MaxSilenceLevel    float64       `toml:"max_silence_level"`
	MinSilenceDuration time.Duration `toml:"min_silence_duration"`
	SampleRate         int           `toml:"sample_rate"`
	StepDuration       time.Duration `toml:"step_duration"`
}

PCMSilenceDetectorOptions represents a PCM silence detector options

type PadOption added in v0.0.10

type PadOption func(p *bytesPadder)

PadOption represents a Pad option

type Piper added in v0.43.0

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

Piper doesn't block on writes. It will block on reads unless you provide a ReadTimeout in which case it will return an optional error, after the provided timeout, if no read is available. When closing the piper, it will interrupt any ongoing read/future writes and return io.EOF. Piper doesn't handle multiple readers at the same time.

func NewPiper added in v0.43.0

func NewPiper(o PiperOptions) *Piper

func (*Piper) Close added in v0.43.0

func (p *Piper) Close() error

func (*Piper) Read added in v0.43.0

func (p *Piper) Read(i []byte) (n int, err error)

func (*Piper) Write added in v0.43.0

func (p *Piper) Write(i []byte) (n int, err error)

type PiperOptions added in v0.43.0

type PiperOptions struct {
	ReadTimeout      time.Duration
	ReadTimeoutError error
}

type Rational added in v0.0.4

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

Rational represents a rational

func NewRational added in v0.0.4

func NewRational(num, den int) *Rational

NewRational creates a new rational

func (*Rational) Den added in v0.0.4

func (r *Rational) Den() int

Den returns the rational den

func (*Rational) MarshalText added in v0.0.4

func (r *Rational) MarshalText() (b []byte, err error)

MarshalText implements the TextMarshaler interface

func (*Rational) Num added in v0.0.4

func (r *Rational) Num() int

Num returns the rational num

func (*Rational) ToFloat64 added in v0.0.4

func (r *Rational) ToFloat64() float64

ToFloat64 returns the rational as a float64

func (*Rational) UnmarshalText added in v0.0.4

func (r *Rational) UnmarshalText(b []byte) (err error)

UnmarshalText implements the TextUnmarshaler interface

type SSHSession added in v0.0.5

type SSHSession interface {
	Run(string) error
	Start(string) error
	StdinPipe() (io.WriteCloser, error)
	Wait() error
}

SSHSession represents an SSH Session

type SSHSessionFunc added in v0.0.5

type SSHSessionFunc func() (s SSHSession, c *Closer, err error)

SSHSessionFunc represents a func that can return an SSHSession

type Semaphore added in v0.43.0

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

func CreateSemaphore added in v0.46.0

func CreateSemaphore(key, flags int) (*Semaphore, error)

func OpenSemaphore added in v0.46.0

func OpenSemaphore(key int) (*Semaphore, error)

func (*Semaphore) Close added in v0.43.0

func (s *Semaphore) Close() error

func (*Semaphore) Key added in v0.43.0

func (s *Semaphore) Key() int

func (*Semaphore) Lock added in v0.43.0

func (s *Semaphore) Lock() error

func (*Semaphore) Unlock added in v0.43.0

func (s *Semaphore) Unlock() error

type SemaphoredSharedMemoryReadOptions added in v0.46.0

type SemaphoredSharedMemoryReadOptions struct {
	SemaphoreKey    int
	SharedMemoryAt  int64
	SharedMemoryKey int
	Size            int
}

type SemaphoredSharedMemoryReader added in v0.46.0

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

func NewSemaphoredSharedMemoryReader added in v0.46.0

func NewSemaphoredSharedMemoryReader() *SemaphoredSharedMemoryReader

func (*SemaphoredSharedMemoryReader) Close added in v0.46.0

func (r *SemaphoredSharedMemoryReader) Close()

func (*SemaphoredSharedMemoryReader) ReadBytes added in v0.46.0

type SemaphoredSharedMemoryWriter added in v0.46.0

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

func NewSemaphoredSharedMemoryWriter added in v0.46.0

func NewSemaphoredSharedMemoryWriter() *SemaphoredSharedMemoryWriter

func (*SemaphoredSharedMemoryWriter) Close added in v0.46.0

func (w *SemaphoredSharedMemoryWriter) Close()

func (*SemaphoredSharedMemoryWriter) Write added in v0.46.0

func (*SemaphoredSharedMemoryWriter) WriteBytes added in v0.46.0

type ServeHTTPOptions added in v0.0.2

type ServeHTTPOptions struct {
	Addr    string
	Handler http.Handler
}

ServeHTTPOptions represents serve options

type SeverityCtxLogger added in v0.1.0

type SeverityCtxLogger interface {
	DebugC(ctx context.Context, v ...interface{})
	DebugCf(ctx context.Context, format string, v ...interface{})
	ErrorC(ctx context.Context, v ...interface{})
	ErrorCf(ctx context.Context, format string, v ...interface{})
	FatalC(ctx context.Context, v ...interface{})
	FatalCf(ctx context.Context, format string, v ...interface{})
	InfoC(ctx context.Context, v ...interface{})
	InfoCf(ctx context.Context, format string, v ...interface{})
	WarnC(ctx context.Context, v ...interface{})
	WarnCf(ctx context.Context, format string, v ...interface{})
}

SeverityCtxLogger represents a severity with context logger

type SeverityLogger added in v0.0.4

type SeverityLogger interface {
	Debug(v ...interface{})
	Debugf(format string, v ...interface{})
	Error(v ...interface{})
	Errorf(format string, v ...interface{})
	Info(v ...interface{})
	Infof(format string, v ...interface{})
	Warn(v ...interface{})
	Warnf(format string, v ...interface{})
}

SeverityLogger represents a severity logger

type SeverityWriteCtxLogger added in v0.35.0

type SeverityWriteCtxLogger interface {
	WriteC(ctx context.Context, l LoggerLevel, v ...interface{})
	WriteCf(ctx context.Context, l LoggerLevel, format string, v ...interface{})
}

type SeverityWriteLogger added in v0.35.0

type SeverityWriteLogger interface {
	Write(l LoggerLevel, v ...interface{})
	Writef(l LoggerLevel, format string, v ...interface{})
}

type SharedMemory added in v0.43.0

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

func CreateSharedMemory added in v0.43.0

func CreateSharedMemory(key, size, flags int) (*SharedMemory, error)

func OpenSharedMemory added in v0.43.0

func OpenSharedMemory(key int) (*SharedMemory, error)

func (*SharedMemory) Close added in v0.43.0

func (w *SharedMemory) Close() error

func (*SharedMemory) Key added in v0.43.0

func (w *SharedMemory) Key() int

func (*SharedMemory) Pointer added in v0.43.0

func (w *SharedMemory) Pointer() unsafe.Pointer

func (*SharedMemory) ReadBytes added in v0.43.0

func (w *SharedMemory) ReadBytes(size int) ([]byte, error)

func (*SharedMemory) Write added in v0.43.0

func (w *SharedMemory) Write(src unsafe.Pointer, size int) error

func (*SharedMemory) WriteBytes added in v0.43.0

func (w *SharedMemory) WriteBytes(b []byte) error

type SignalHandler added in v0.0.2

type SignalHandler func(s os.Signal)

SignalHandler represents a func that can handle a signal

func LoggerSignalHandler added in v0.6.0

func LoggerSignalHandler(l SeverityLogger, ignoredSignals ...os.Signal) SignalHandler

LoggerSignalHandler returns a SignalHandler that logs the signal

func TermSignalHandler added in v0.0.2

func TermSignalHandler(f func()) SignalHandler

TermSignalHandler returns a SignalHandler that is executed only on a term signal

type SortInt64Slice added in v0.0.6

type SortInt64Slice []int64

SortInt64Slice attaches the methods of Interface to []int64, sorting in increasing order.

func (SortInt64Slice) Len added in v0.0.6

func (p SortInt64Slice) Len() int

func (SortInt64Slice) Less added in v0.0.6

func (p SortInt64Slice) Less(i, j int) bool

func (SortInt64Slice) Swap added in v0.0.6

func (p SortInt64Slice) Swap(i, j int)

type SortUint64Slice added in v0.42.0

type SortUint64Slice []uint64

SortUint64Slice attaches the methods of Interface to []uint64, sorting in increasing order.

func (SortUint64Slice) Len added in v0.42.0

func (p SortUint64Slice) Len() int

func (SortUint64Slice) Less added in v0.42.0

func (p SortUint64Slice) Less(i, j int) bool

func (SortUint64Slice) Swap added in v0.42.0

func (p SortUint64Slice) Swap(i, j int)

type StatMetadata added in v0.0.4

type StatMetadata struct {
	Description string
	Label       string
	Name        string
	Unit        string
}

StatMetadata represents a stat metadata

type StatOptions added in v0.13.0

type StatOptions struct {
	Metadata *StatMetadata
	// Either a StatValuer or StatValuerOverTime
	Valuer interface{}
}

StatOptions represents stat options

type StatValue added in v0.13.0

type StatValue struct {
	*StatMetadata
	Value interface{}
}

StatValue represents a stat value

type StatValuer added in v0.33.0

type StatValuer interface {
	Value(delta time.Duration) interface{}
}

StatValuer represents a stat valuer

type StatValuerFunc added in v0.37.0

type StatValuerFunc func(d time.Duration) interface{}

func (StatValuerFunc) Value added in v0.37.0

func (f StatValuerFunc) Value(d time.Duration) interface{}

type Stater added in v0.0.4

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

Stater is an object that can compute and handle stats

func NewStater added in v0.0.4

func NewStater(o StaterOptions) *Stater

NewStater creates a new stater

func (*Stater) AddStats added in v0.13.0

func (s *Stater) AddStats(os ...StatOptions)

AddStats adds stats

func (*Stater) DelStats added in v0.13.0

func (s *Stater) DelStats(os ...StatOptions)

DelStats deletes stats

func (*Stater) Start added in v0.0.4

func (s *Stater) Start(ctx context.Context)

Start starts the stater

func (*Stater) Stop added in v0.0.4

func (s *Stater) Stop()

Stop stops the stater

type StaterOptions added in v0.0.4

type StaterOptions struct {
	HandleFunc StatsHandleFunc
	Period     time.Duration
}

StaterOptions represents stater options

type StatsHandleFunc added in v0.0.4

type StatsHandleFunc func(stats []StatValue)

StatsHandleFunc is a method that can handle stat values

type StdLogger added in v0.0.4

type StdLogger interface {
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
	Print(v ...interface{})
	Printf(format string, v ...interface{})
}

StdLogger represents a standard logger

type Task added in v0.0.2

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

Task represents a task

func (*Task) Do added in v0.0.2

func (t *Task) Do(f func())

Do executes the task

func (*Task) Done added in v0.0.2

func (t *Task) Done()

Done indicates the task is done

func (*Task) NewSubTask added in v0.0.2

func (t *Task) NewSubTask() *Task

NewSubTask creates a new sub task

func (*Task) Wait added in v0.0.2

func (t *Task) Wait()

Wait waits for first level subtasks to be finished

type TaskFunc added in v0.0.2

type TaskFunc func() *Task

TaskFunc represents a function that can create a new task

type Templater added in v0.0.3

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

Templater represents an object capable of storing and parsing templates

func NewTemplater added in v0.0.3

func NewTemplater() *Templater

NewTemplater creates a new templater

func (*Templater) AddLayout added in v0.0.3

func (t *Templater) AddLayout(c string)

AddLayout adds a new layout

func (*Templater) AddLayoutsFromDir added in v0.0.3

func (t *Templater) AddLayoutsFromDir(dirPath, ext string) (err error)

AddLayoutsFromDir walks through a dir and add files as layouts

func (*Templater) AddTemplate added in v0.0.3

func (t *Templater) AddTemplate(path, content string) (err error)

AddTemplate adds a new template

func (*Templater) AddTemplatesFromDir added in v0.0.3

func (t *Templater) AddTemplatesFromDir(dirPath, ext string) (err error)

AddTemplatesFromDir walks through a dir and add files as templates

func (*Templater) DelTemplate added in v0.0.3

func (t *Templater) DelTemplate(path string)

DelTemplate deletes a template

func (*Templater) Parse added in v0.0.3

func (t *Templater) Parse(content string) (o *template.Template, err error)

Parse parses the content of a template

func (*Templater) Template added in v0.0.3

func (t *Templater) Template(path string) (tpl *template.Template, ok bool)

Template retrieves a templates

type TestLogger added in v0.24.0

type TestLogger interface {
	Error(v ...interface{})
	Errorf(format string, v ...interface{})
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
	Log(v ...interface{})
	Logf(format string, v ...interface{})
}

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp represents a timestamp you can marshal and umarshal

func NewTimestamp

func NewTimestamp(t time.Time) *Timestamp

NewTimestamp creates a new timestamp

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSONMarshaler interface

func (Timestamp) MarshalText

func (t Timestamp) MarshalText() (text []byte, err error)

MarshalText implements the TextMarshaler interface

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(text []byte) error

UnmarshalJSON implements the JSONUnmarshaler interface

func (*Timestamp) UnmarshalText

func (t *Timestamp) UnmarshalText(text []byte) (err error)

UnmarshalText implements the TextUnmarshaler interface

type Translator added in v0.3.0

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

Translator represents an object capable of translating stuff

func NewTranslator added in v0.3.0

func NewTranslator(o TranslatorOptions) (t *Translator)

NewTranslator creates a new Translator

func (*Translator) HTTPMiddleware added in v0.3.0

func (t *Translator) HTTPMiddleware(h http.Handler) http.Handler

HTTPMiddleware is the Translator HTTP middleware

func (*Translator) LanguageCtx added in v0.4.0

func (t *Translator) LanguageCtx(ctx context.Context) string

LanguageCtx returns the translator language from the context, or the default language if not in the context

func (*Translator) ParseDir added in v0.3.0

func (t *Translator) ParseDir(dirPath string) (err error)

ParseDir adds translations located in ".json" files in the specified dir If ".json" files are located in child dirs, keys will be prefixed with their paths

func (*Translator) ParseFile added in v0.3.0

func (t *Translator) ParseFile(dirPath, path string) (err error)

ParseFile adds translation located in the provided path

func (*Translator) Translate added in v0.3.0

func (t *Translator) Translate(language, key string) string

Translate translates a key into a specific language

func (*Translator) TranslateC added in v0.32.0

func (t *Translator) TranslateC(ctx context.Context, key string) string

TranslateC translates a key using the language specified in the context

func (*Translator) TranslateCf added in v0.32.0

func (t *Translator) TranslateCf(ctx context.Context, key string, args ...interface{}) string

func (*Translator) TranslateCtx added in v0.3.0

func (t *Translator) TranslateCtx(ctx context.Context, key string) string

TranslateCtx is an alias for TranslateC

func (*Translator) Translatef added in v0.32.0

func (t *Translator) Translatef(language, key string, args ...interface{}) string

Translatef translates a key into a specific language with optional formatting args

type TranslatorOptions added in v0.3.0

type TranslatorOptions struct {
	DefaultLanguage string
	ValidLanguages  []string
}

TranslatorOptions represents Translator options

type Worker added in v0.0.2

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

Worker represents an object capable of blocking, handling signals and stopping

func NewWorker added in v0.0.2

func NewWorker(o WorkerOptions) (w *Worker)

NewWorker builds a new worker

func (*Worker) Context added in v0.0.2

func (w *Worker) Context() context.Context

Context returns the worker's context

func (*Worker) HandleSignals added in v0.0.2

func (w *Worker) HandleSignals(hs ...SignalHandler)

HandleSignals handles signals

func (*Worker) Logger added in v0.0.2

func (w *Worker) Logger() SeverityLogger

Logger returns the worker's logger

func (*Worker) NewTask added in v0.0.2

func (w *Worker) NewTask() *Task

NewTask creates a new task

func (*Worker) Stop added in v0.0.2

func (w *Worker) Stop()

Stop stops the Worker

func (*Worker) Wait added in v0.0.2

func (w *Worker) Wait()

Wait is a blocking pattern

type WorkerOptions added in v0.0.3

type WorkerOptions struct {
	Logger StdLogger
}

WorkerOptions represents worker options

type WriterAdapter added in v0.0.3

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

WriterAdapter represents an object that can adapt a Writer

func NewWriterAdapter added in v0.0.3

func NewWriterAdapter(o WriterAdapterOptions) *WriterAdapter

NewWriterAdapter creates a new WriterAdapter

func (*WriterAdapter) Close added in v0.0.3

func (w *WriterAdapter) Close() error

Close closes the adapter properly

func (*WriterAdapter) Write added in v0.0.3

func (w *WriterAdapter) Write(i []byte) (n int, err error)

Write implements the io.Writer interface

type WriterAdapterOptions added in v0.0.3

type WriterAdapterOptions struct {
	Callback func(i []byte)
	Split    []byte
}

WriterAdapterOptions represents WriterAdapter options

Jump to

Keyboard shortcuts

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