util

package
v0.0.2-alpha Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: GPL-3.0 Imports: 36 Imported by: 104

Documentation

Overview

Package util provides tiny featured funcs.

Index

Constants

This section is empty.

Variables

View Source
var (
	ContextTimerPoolGet = func() *ContextTimer {
		return contextTimerPool.Get().(*ContextTimer)
	}
	ContextTimerPoolPut = func(ct *ContextTimer) {
		ct.Lock()
		ct.ContextDaemon = nil
		ct.id = TimerID("")
		ct.interval = nil
		ct.callback = nil
		ct.c = 0
		ct.Unlock()

		contextTimerPool.Put(ct)
	}
)
View Source
var (
	ErrDaemonAlreadyStarted = NewError("daemon already started")
	ErrDaemonAlreadyStopped = NewError("daemon already stopped")
)
View Source
var (
	ErrFound          = NewError("found")
	ErrNotFound       = NewError("not found")
	ErrDuplicated     = NewError("duplicated")
	ErrWrongType      = NewError("wrong type")
	ErrNotImplemented = NewError("not implemented")
	ErrInternal       = NewError("internal error")
)
View Source
var (
	ErrLockedSetIgnore = NewError("ignore to set locked value")
	ErrLockedMapClosed = NewError("locked map closed")
)
View Source
var ErrInvalid = NewError("invalid")
View Source
var ErrStopTimer = NewError("stop timer")
View Source
var ErrWorkerContextCanceled = NewError("context canceled in worker")
View Source
var MinVersionLength = 2
View Source
var (
	ULIDLen = len([]byte(ULID().String()))
)

Functions

func AwareContext

func AwareContext(ctx context.Context, f func() error) error

func BatchWork

func BatchWork(
	ctx context.Context,
	size, limit uint64,
	pref func(_ context.Context, last uint64) error,
	f func(_ context.Context, i, last uint64) error,
) error

BatchWork runs f by limit size in worker. For example, size=5 limit=2 are given, 1. Run worker(0,1) 2. Run worker(2,3) 3. Run worker(4), done.

func BigBytesToInt64

func BigBytesToInt64(b []byte) (int64, error)

func BytesToInt64

func BytesToInt64(b []byte) (int64, error)

func BytesToUint64

func BytesToUint64(b []byte) (uint64, error)

func CheckIsValiderSlice

func CheckIsValiderSlice[T IsValider](b []byte, allowNil bool, vs []T) error

func CheckIsValiders

func CheckIsValiders(b []byte, allowNil bool, vs ...IsValider) error

func CleanDirectory

func CleanDirectory(root string, filter func(path string) bool) error

func ConcatByterSlice

func ConcatByterSlice[T Byter](bs []T) []byte

func ConcatByters

func ConcatByters(bs ...Byter) []byte

func ConcatBytesSlice

func ConcatBytesSlice(sl ...[]byte) []byte

func CountFilteredSlice

func CountFilteredSlice[T any](s []T, f func(T) bool) (n int)

func DecodeHash

func DecodeHash(s string) []byte

func EncodeHash

func EncodeHash(b []byte) string

func EnsureRead

func EnsureRead(r io.Reader, b []byte) (int, error)

func Filter2Slices

func Filter2Slices[T any, Y any](a []T, b []Y, f func(T, Y) bool) []T

func FilterMap

func FilterMap[T any, Y comparable](s map[Y]T, f func(Y, T) bool) []T

func FilterSlice

func FilterSlice[T any](s []T, f func(T) bool) []T

func Float64ToBytes

func Float64ToBytes(i float64) []byte

func FuncCaller

func FuncCaller(skip int) errors.Frame

func InSlice

func InSlice[T comparable](s []T, n T) int

func InSliceFunc

func InSliceFunc[T any](s []T, f func(T) bool) int

func Int64ToBigBytes

func Int64ToBigBytes(i int64) []byte

func Int64ToBytes

func Int64ToBytes(i int64) []byte

func InterfaceSetValue

func InterfaceSetValue(v, target interface{}) error

func IsDuplicatedSlice

func IsDuplicatedSlice[T any](s []T, keyf func(T) (bool, string)) (map[string]T, bool)

func IsNilJSON

func IsNilJSON(b []byte) bool

func IsValidURL

func IsValidURL(u *url.URL) error

func LengthedBytes

func LengthedBytes(w io.Writer, b []byte) error

func LoadFromContext

func LoadFromContext(ctx context.Context, a ...interface{}) error

func LoadFromContextOK

func LoadFromContextOK(ctx context.Context, a ...interface{}) error

func MarshalJSON

func MarshalJSON(v interface{}) ([]byte, error)

func MarshalJSONIndent

func MarshalJSONIndent(i interface{}) ([]byte, error)

func MustMarshalJSON

func MustMarshalJSON(i interface{}) []byte

func MustMarshalJSONIndent

func MustMarshalJSONIndent(i interface{}) []byte

func MustMarshalJSONIndentString

func MustMarshalJSONIndentString(i interface{}) string

func NewLengthedBytesSlice

func NewLengthedBytesSlice(version byte, m [][]byte) ([]byte, error)

func NormalizeTime

func NormalizeTime(t time.Time) time.Time

NormalizeTime clear the nanoseconds part from Time and make time to UTC. "2009-11-10T23:00:00.00101010Z" -> "2009-11-10T23:00:00.001Z",

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

func ParseRFC3339

func ParseRFC3339(s string) (time.Time, error)

ParseRFC3339 parses RFC3339 string.

func RFC3339

func RFC3339(t time.Time) string

RFC3339 formats time.Time to RFC3339Nano string.

func ReadLengthedBytes

func ReadLengthedBytes(b []byte) (_ []byte, left []byte, _ error)

func ReadLengthedBytesFromReader

func ReadLengthedBytesFromReader(r io.Reader) ([]byte, error)

func ReadLengthedBytesSlice

func ReadLengthedBytesSlice(b []byte) (version byte, m [][]byte, left []byte, _ error)

func Retry

func Retry(ctx context.Context, f func() (bool, error), limit int, interval time.Duration) error

func RunDistributeWorker

func RunDistributeWorker(
	ctx context.Context, size uint64, errch chan error, f func(ctx context.Context, i, jobid uint64) error,
) error

func RunErrgroupWorker

func RunErrgroupWorker(ctx context.Context, size uint64, f func(ctx context.Context, i, jobid uint64) error) error

func RunErrgroupWorkerByJobs

func RunErrgroupWorkerByJobs(ctx context.Context, jobs ...ContextWorkerCallback) error

func SHA256Checksum

func SHA256Checksum(b []byte) string

func StringErrorFunc

func StringErrorFunc(m string, a ...interface{}) func(error, string, ...interface{}) error

func TimeEqual

func TimeEqual(a, b time.Time) bool

func TimeString

func TimeString(t time.Time) string

func TraverseSlice

func TraverseSlice[T any](s []T, f func(int, T) error) error

func ULID

func ULID() ulid.ULID

func UUID

func UUID() uuid.UUID

func Uint64ToBigBytes

func Uint64ToBigBytes(i uint64) []byte

func Uint64ToBytes

func Uint64ToBytes(i uint64) []byte

func Uint8ToBytes

func Uint8ToBytes(i uint8) []byte

func UintToBytes

func UintToBytes(i uint) []byte

func UnmarshalJSON

func UnmarshalJSON(b []byte, v interface{}) error

func WriteLengthedBytesSlice

func WriteLengthedBytesSlice(w io.Writer, version byte, m [][]byte) error

func ZerologMarshalStack

func ZerologMarshalStack(err error) interface{}

Types

type BaseSemWorker

type BaseSemWorker struct {
	Ctx        context.Context //nolint:containedctx //...
	Sem        *semaphore.Weighted
	Cancel     func()
	NewJobFunc func(context.Context, uint64, ContextWorkerCallback)

	N        int64
	JobCount uint64
	// contains filtered or unexported fields
}

func NewBaseSemWorker

func NewBaseSemWorker(ctx context.Context, semsize int64) *BaseSemWorker

func (*BaseSemWorker) Close

func (wk *BaseSemWorker) Close()

func (*BaseSemWorker) Done

func (wk *BaseSemWorker) Done()

func (*BaseSemWorker) Jobs

func (wk *BaseSemWorker) Jobs() uint64

func (*BaseSemWorker) LazyCancel

func (wk *BaseSemWorker) LazyCancel(timeout time.Duration)

func (*BaseSemWorker) NewJob

func (wk *BaseSemWorker) NewJob(callback ContextWorkerCallback) error

func (*BaseSemWorker) Wait

func (wk *BaseSemWorker) Wait() error

func (*BaseSemWorker) WaitChan

func (wk *BaseSemWorker) WaitChan() chan error

type BuildInfo

type BuildInfo struct {
	Branch    string
	Commit    string
	BuildTime time.Time
	Version   Version
}

func ParseBuildInfo

func ParseBuildInfo(version, branch, commit, buildTime string) (BuildInfo, error)

func (BuildInfo) String

func (bi BuildInfo) String() string

type Byter

type Byter interface {
	Bytes() []byte
}

type BytesToByter

type BytesToByter []byte

func (BytesToByter) Bytes

func (b BytesToByter) Bytes() []byte

type ChecksumReader

type ChecksumReader interface {
	io.ReadCloser
	Checksum() string
}

type ChecksumWriter

type ChecksumWriter interface {
	io.WriteCloser
	Name() string
	Checksum() string
}

type ContextDaemon

type ContextDaemon struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewContextDaemon

func NewContextDaemon(startfunc func(context.Context) error) *ContextDaemon

func (*ContextDaemon) IsStarted

func (dm *ContextDaemon) IsStarted() bool

func (*ContextDaemon) Start

func (dm *ContextDaemon) Start(ctx context.Context) error

func (*ContextDaemon) Stop

func (dm *ContextDaemon) Stop() error

func (*ContextDaemon) Wait

func (dm *ContextDaemon) Wait(ctx context.Context) <-chan error

type ContextKey

type ContextKey string

type ContextTimer

type ContextTimer struct {
	*ContextDaemon
	*logging.Logging

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewContextTimer

func NewContextTimer(id TimerID, interval time.Duration, callback func(int) (bool, error)) *ContextTimer

func (*ContextTimer) ID

func (ct *ContextTimer) ID() TimerID

func (*ContextTimer) Reset

func (ct *ContextTimer) Reset() error

func (*ContextTimer) SetInterval

func (ct *ContextTimer) SetInterval(f func(int, time.Duration) time.Duration) Timer

func (*ContextTimer) Stop

func (ct *ContextTimer) Stop() error

type ContextWorkerCallback

type ContextWorkerCallback func(ctx context.Context, jobid uint64) error

type Daemon

type Daemon interface {
	Start(context.Context) error
	Stop() error
}

type DefaultJSONMarshaled

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

func (DefaultJSONMarshaled) Marshaled

func (m DefaultJSONMarshaled) Marshaled() ([]byte, bool)

func (*DefaultJSONMarshaled) SetMarshaled

func (m *DefaultJSONMarshaled) SetMarshaled(b []byte)

type DistributeWorker

type DistributeWorker struct {
	*BaseSemWorker
	// contains filtered or unexported fields
}

func NewDistributeWorker

func NewDistributeWorker(ctx context.Context, semsize int64, errch chan error) *DistributeWorker

func (*DistributeWorker) Close

func (wk *DistributeWorker) Close()

type DummyByter

type DummyByter func() []byte

func (DummyByter) Bytes

func (d DummyByter) Bytes() []byte

type DummyChecksumReader

type DummyChecksumReader struct {
	io.ReadCloser
	// contains filtered or unexported fields
}

func NewDummyChecksumReader

func NewDummyChecksumReader(f io.ReadCloser, cr ChecksumReader) *DummyChecksumReader

func (*DummyChecksumReader) Checksum

func (r *DummyChecksumReader) Checksum() string

type DummyChecksumWriter

type DummyChecksumWriter struct {
	io.WriteCloser
	// contains filtered or unexported fields
}

func NewDummyChecksumWriter

func NewDummyChecksumWriter(f io.WriteCloser, cw ChecksumWriter) *DummyChecksumWriter

func (*DummyChecksumWriter) Checksum

func (w *DummyChecksumWriter) Checksum() string

func (*DummyChecksumWriter) Name

func (w *DummyChecksumWriter) Name() string

type DummyIsValider

type DummyIsValider func([]byte) error

func (DummyIsValider) IsValid

func (iv DummyIsValider) IsValid(b []byte) error

type ErrgroupWorker

type ErrgroupWorker struct {
	*BaseSemWorker
	// contains filtered or unexported fields
}

func NewErrgroupWorker

func NewErrgroupWorker(ctx context.Context, semsize int64) *ErrgroupWorker

func (*ErrgroupWorker) Close

func (wk *ErrgroupWorker) Close()

func (*ErrgroupWorker) RunChan

func (wk *ErrgroupWorker) RunChan() chan error

func (*ErrgroupWorker) Wait

func (wk *ErrgroupWorker) Wait() error

type Error

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

func NewError

func NewError(s string, a ...interface{}) Error

func (Error) Call

func (er Error) Call() Error

func (Error) Error

func (er Error) Error() string

func (Error) Errorf

func (er Error) Errorf(s string, a ...interface{}) Error

Errorf formats strings. It does not support `%w` error formatting.

func (Error) Format

func (er Error) Format(st fmt.State, verb rune)

func (Error) Is

func (er Error) Is(err error) bool

func (Error) StackTrace

func (er Error) StackTrace() errors.StackTrace

func (Error) Unwrap

func (er Error) Unwrap() error

func (Error) Wrap

func (er Error) Wrap(err error) Error

func (Error) Wrapf

func (er Error) Wrapf(err error, s string, a ...interface{}) Error

Wrapf formats strings with error.

type FuncChain

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

func NewFuncChain

func NewFuncChain() *FuncChain

func (*FuncChain) Add

func (c *FuncChain) Add(f func() (bool, error)) *FuncChain

func (*FuncChain) Run

func (c *FuncChain) Run() error

type GCache

type GCache[K constraints.Ordered, V any] struct {
	// contains filtered or unexported fields
}

func NewLFUGCache

func NewLFUGCache[K constraints.Ordered, V any](_ K, _ V, size int) *GCache[K, V]

func NewLRUGCache

func NewLRUGCache[K constraints.Ordered, V any](_ K, _ V, size int) *GCache[K, V]

func (*GCache[K, V]) Close

func (c *GCache[K, V]) Close()

func (*GCache[K, V]) Exists

func (c *GCache[K, V]) Exists(key K) bool

func (*GCache[K, V]) Get

func (c *GCache[K, V]) Get(key string) (v V, found bool)

func (*GCache[K, V]) Purge

func (c *GCache[K, V]) Purge()

func (*GCache[K, V]) Set

func (c *GCache[K, V]) Set(key K, v V, expire time.Duration)

type GCacheObjectPool

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

func NewGCacheObjectPool

func NewGCacheObjectPool(size int) *GCacheObjectPool

func (*GCacheObjectPool) Close

func (po *GCacheObjectPool) Close()

func (*GCacheObjectPool) Exists

func (po *GCacheObjectPool) Exists(key string) bool

func (*GCacheObjectPool) Get

func (po *GCacheObjectPool) Get(key string) (interface{}, bool)

func (*GCacheObjectPool) Set

func (po *GCacheObjectPool) Set(key string, v interface{}, expire *time.Duration)

type GzipReader

type GzipReader struct {
	io.Reader
	// contains filtered or unexported fields
}

GzipReader closes the underlying reader too.

func NewGzipReader

func NewGzipReader(f io.Reader) (*GzipReader, error)

func (*GzipReader) Close

func (r *GzipReader) Close() error

func (*GzipReader) Read

func (r *GzipReader) Read(p []byte) (int, error)

type GzipWriter

type GzipWriter struct {
	io.Writer

	sync.Mutex
	// contains filtered or unexported fields
}

GzipWriter closes the underlying reader too.

func NewGzipWriter

func NewGzipWriter(f io.Writer) *GzipWriter

func (*GzipWriter) Close

func (w *GzipWriter) Close() error

func (*GzipWriter) Write

func (w *GzipWriter) Write(p []byte) (int, error)

type Hash

type Hash interface {
	Equal(Hash) bool
	fmt.Stringer // NOTE usually String() value is the base58 encoded of Bytes()
	Byter
	IsValider
}

type HashByter

type HashByter interface {
	// HashBytes is uses to generate hash
	HashBytes() []byte
}

type HashChecksumReader

type HashChecksumReader struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewHashChecksumReader

func NewHashChecksumReader(r io.ReadCloser, h hash.Hash) *HashChecksumReader

func (*HashChecksumReader) Checksum

func (r *HashChecksumReader) Checksum() string

func (*HashChecksumReader) Close

func (r *HashChecksumReader) Close() error

func (*HashChecksumReader) Read

func (r *HashChecksumReader) Read(b []byte) (int, error)

type HashChecksumWriter

type HashChecksumWriter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewHashChecksumWriter

func NewHashChecksumWriter(fname string, w io.WriteCloser, h hash.Hash) *HashChecksumWriter

func (*HashChecksumWriter) Checksum

func (w *HashChecksumWriter) Checksum() string

func (*HashChecksumWriter) Close

func (w *HashChecksumWriter) Close() error

func (*HashChecksumWriter) Name

func (w *HashChecksumWriter) Name() string

func (*HashChecksumWriter) Write

func (w *HashChecksumWriter) Write(b []byte) (int, error)

type Hasher

type Hasher interface {
	Hash() Hash
}

type IsValider

type IsValider interface {
	IsValid([]byte) error
}

type JSONMarshaled

type JSONMarshaled interface {
	Marshaled() ([]byte, bool)
}

type JSONSetMarshaled

type JSONSetMarshaled interface {
	SetMarshaled([]byte)
}

type Locked

type Locked[T any] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func EmptyLocked

func EmptyLocked[T any](T) *Locked[T]

func NewLocked

func NewLocked[T any](v T) *Locked[T]

func (*Locked[T]) Empty

func (l *Locked[T]) Empty(f func(_ T, isempty bool) error) error

func (*Locked[T]) EmptyValue

func (l *Locked[T]) EmptyValue() *Locked[T]

func (*Locked[T]) Get

func (l *Locked[T]) Get(create func() (T, error)) (v T, _ error)

func (*Locked[T]) Set

func (l *Locked[T]) Set(f func(_ T, isempty bool) (T, error)) (v T, _ error)

func (*Locked[T]) SetValue

func (l *Locked[T]) SetValue(v T) *Locked[T]

func (*Locked[T]) Value

func (l *Locked[T]) Value() (v T, isempty bool)

type LockedMap

type LockedMap[K lockedMapKeys, V any] interface {
	Exists(key K) (found bool)
	Value(key K) (value V, found bool)
	SetValue(key K, value V) (found bool)
	RemoveValue(key K) (removed bool)
	Get(key K, create func() (value V, _ error)) (value V, found bool, _ error)
	Set(key K, f func(_ V, found bool) (value V, _ error)) (value V, _ error)
	Remove(key K, f func(value V) error) (removed bool, _ error)
	Traverse(f func(key K, value V) (keep bool))
	Len() int
	Empty()
	Close()
}

func NewLockedMap

func NewLockedMap[K lockedMapKeys, V any](k K, v V, size int64) (LockedMap[K, V], error)

type ObjectPool

type ObjectPool interface {
	Exists(string) bool
	Get(string) (interface{}, bool)
	Set(string, interface{}, *time.Duration)
}

type ParallelWorker

type ParallelWorker struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewParallelWorker

func NewParallelWorker(bufsize uint) *ParallelWorker

func (*ParallelWorker) Done

func (wk *ParallelWorker) Done()

func (*ParallelWorker) Errors

func (wk *ParallelWorker) Errors() <-chan error

func (*ParallelWorker) FinishedJobs

func (wk *ParallelWorker) FinishedJobs() int

func (*ParallelWorker) IsFinished

func (wk *ParallelWorker) IsFinished() bool

func (*ParallelWorker) Jobs

func (wk *ParallelWorker) Jobs() uint

func (*ParallelWorker) NewJob

func (wk *ParallelWorker) NewJob(j interface{})

func (*ParallelWorker) Run

func (wk *ParallelWorker) Run(callback WorkerCallback) *ParallelWorker

type ReadableJSONDuration

type ReadableJSONDuration time.Duration

func (ReadableJSONDuration) MarshalText

func (d ReadableJSONDuration) MarshalText() ([]byte, error)

func (*ReadableJSONDuration) UnmarshalJSON

func (d *ReadableJSONDuration) UnmarshalJSON(b []byte) error

type ShardedMap

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

func NewShardedMap

func NewShardedMap[K lockedMapKeys, V any](_ K, _ V, size int64) (*ShardedMap[K, V], error)

func (*ShardedMap[K, V]) Close

func (l *ShardedMap[K, V]) Close()

func (*ShardedMap[K, V]) Empty

func (l *ShardedMap[K, V]) Empty()

func (*ShardedMap[K, V]) Exists

func (l *ShardedMap[K, V]) Exists(k K) bool

func (*ShardedMap[K, V]) Get

func (l *ShardedMap[K, V]) Get(k K, create func() (V, error)) (v V, found bool, _ error)

func (*ShardedMap[K, V]) Len

func (l *ShardedMap[K, V]) Len() int

func (*ShardedMap[K, V]) Remove

func (l *ShardedMap[K, V]) Remove(k K, f func(V) error) (bool, error)

func (*ShardedMap[K, V]) RemoveValue

func (l *ShardedMap[K, V]) RemoveValue(k K) bool

func (*ShardedMap[K, V]) Set

func (l *ShardedMap[K, V]) Set(k K, f func(V, bool) (V, error)) (v V, _ error)

func (*ShardedMap[K, V]) SetValue

func (l *ShardedMap[K, V]) SetValue(k K, v V) (found bool)

func (*ShardedMap[K, V]) Traverse

func (l *ShardedMap[K, V]) Traverse(f func(K, V) bool)

func (*ShardedMap[K, V]) Value

func (l *ShardedMap[K, V]) Value(k K) (v V, found bool)

type SingleLockedMap

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

func NewSingleLockedMap

func NewSingleLockedMap[K lockedMapKeys, V any](K, V) *SingleLockedMap[K, V]

func (*SingleLockedMap[K, V]) Close

func (l *SingleLockedMap[K, V]) Close()

func (*SingleLockedMap[K, V]) Empty

func (l *SingleLockedMap[K, V]) Empty()

func (*SingleLockedMap[K, V]) Exists

func (l *SingleLockedMap[K, V]) Exists(k K) bool

func (*SingleLockedMap[K, V]) Get

func (l *SingleLockedMap[K, V]) Get(k K, create func() (V, error)) (v V, found bool, err error)

func (*SingleLockedMap[K, V]) Len

func (l *SingleLockedMap[K, V]) Len() int

func (*SingleLockedMap[K, V]) Remove

func (l *SingleLockedMap[K, V]) Remove(k K, f func(V) error) (bool, error)

func (*SingleLockedMap[K, V]) RemoveValue

func (l *SingleLockedMap[K, V]) RemoveValue(k K) bool

func (*SingleLockedMap[K, V]) Set

func (l *SingleLockedMap[K, V]) Set(k K, f func(_ V, found bool) (V, error)) (V, error)

func (*SingleLockedMap[K, V]) SetValue

func (l *SingleLockedMap[K, V]) SetValue(k K, v V) (found bool)

func (*SingleLockedMap[K, V]) Traverse

func (l *SingleLockedMap[K, V]) Traverse(f func(K, V) bool)

func (*SingleLockedMap[K, V]) Value

func (l *SingleLockedMap[K, V]) Value(k K) (v V, found bool)

type StreamDecoder

type StreamDecoder interface {
	Decode(interface{}) error
}

func NewJSONStreamDecoder

func NewJSONStreamDecoder(r io.Reader) StreamDecoder

type StreamEncoder

type StreamEncoder interface {
	Encode(interface{}) error
}

func NewJSONStreamEncoder

func NewJSONStreamEncoder(w io.Writer) StreamEncoder

type Stringer

type Stringer func() string

func (Stringer) String

func (s Stringer) String() string

type Timer

type Timer interface {
	Daemon
	IsStarted() bool
	ID() TimerID
	SetInterval(func(int, time.Duration) time.Duration) Timer
	Reset() error
}

type TimerID

type TimerID string

func (TimerID) String

func (ti TimerID) String() string

type Timers

type Timers struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Timers handles the multiple timers and controls them selectively.

func NewTimers

func NewTimers(ids []TimerID, allowUnknown bool) *Timers

func (*Timers) IsTimerStarted

func (ts *Timers) IsTimerStarted(id TimerID) bool

func (*Timers) ResetTimer

func (ts *Timers) ResetTimer(id TimerID) error

func (*Timers) SetTimer

func (ts *Timers) SetTimer(timer Timer) error

SetTimer sets the timer with id

func (*Timers) Start

func (ts *Timers) Start(context.Context) error

Start of Timers does nothing

func (*Timers) StartTimers

func (ts *Timers) StartTimers(ids []TimerID, stopOthers bool) error

StartTimers starts timers with the given ids, before starting timers, stops the other timers if stopOthers is true.

func (*Timers) Started

func (ts *Timers) Started() []TimerID

func (*Timers) Stop

func (ts *Timers) Stop() error

Stop of Timers will stop all the timers

func (*Timers) StopTimers

func (ts *Timers) StopTimers(ids []TimerID) error

func (*Timers) StopTimersAll

func (ts *Timers) StopTimersAll() error

type ULIDPool

type ULIDPool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewULIDPool

func NewULIDPool() *ULIDPool

func (*ULIDPool) New

func (u *ULIDPool) New() ulid.ULID

type Version

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

func EnsureParseVersion

func EnsureParseVersion(s string) Version

EnsureParseVersion tries to parse version string, but skips to check IsValid().

func MustNewVersion

func MustNewVersion(s string) Version

func ParseVersion

func ParseVersion(s string) (Version, error)

ParseVersion tries to parse version string and also checks IsValid().

func (Version) Compare

func (v Version) Compare(b Version) int

func (Version) IsCompatible

func (v Version) IsCompatible(b Version) bool

IsCompatible checks if the given version is compatible to the target. The compatible conditions are major matches.

func (Version) IsEmpty

func (v Version) IsEmpty() bool

func (Version) IsValid

func (v Version) IsValid([]byte) error

func (Version) Major

func (v Version) Major() uint64

func (Version) MarshalText

func (v Version) MarshalText() ([]byte, error)

func (Version) Minor

func (v Version) Minor() uint64

func (Version) Patch

func (v Version) Patch() uint64

func (Version) Prerelease

func (v Version) Prerelease() string

func (Version) String

func (v Version) String() string

func (*Version) UnmarshalText

func (v *Version) UnmarshalText(b []byte) error

type WorkerCallback

type WorkerCallback func(jobid uint, arg interface{}) error

Directories

Path Synopsis
Package encoder supports to encode and decode structs in multiple formats.
Package encoder supports to encode and decode structs in multiple formats.
json
Package jsonenc support encoding and decoding by json.
Package jsonenc support encoding and decoding by json.
Package fixedtree provides tree structures.
Package fixedtree provides tree structures.
Package hint provides to handle structs and data with type and it's version.
Package hint provides to handle structs and data with type and it's version.
Package localtime provides time related funcs.
Package localtime provides time related funcs.
Package logging supports the consistent logging for modules.
Package logging supports the consistent logging for modules.
Package ps is processes
Package ps is processes
Package valuehash provides valuehashes.
Package valuehash provides valuehashes.

Jump to

Keyboard shortcuts

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