Documentation ¶
Overview ¶
Package util provides tiny featured funcs.
Index ¶
- Variables
- func AssertInterfaceValue[T any](v interface{}) (t T, _ error)
- func AwareContext(ctx context.Context, f func(context.Context) error) error
- func AwareContextValue[T any](ctx context.Context, f func(context.Context) (T, error)) (T, error)
- func BatchWork(ctx context.Context, size, limit int64, ...) error
- func BigBytesToInt64(b []byte) (int64, error)
- func BoolToBytes(b bool) []byte
- func BytesToInt64(b []byte) (int64, error)
- func BytesToUint64(b []byte) (uint64, error)
- func CheckIsValiderSlice[T IsValider](b []byte, allowNil bool, vs []T) error
- func CheckIsValiders(b []byte, allowNil bool, vs ...IsValider) error
- func CleanDirectory(root string, filter func(path string) bool) error
- func CompactAppendSlice[T any](size int) (add func(T) bool, done func() []T)
- func ConcatByterSlice[T Byter](bs []T) []byte
- func ConcatByters(bs ...Byter) []byte
- func ConcatBytesSlice(sl ...[]byte) []byte
- func ContextWithValues(ctx context.Context, v map[ContextKey]interface{}) context.Context
- func CountFilteredSlice[T any](s []T, f func(T) bool) (n int)
- func DecodeHash(s string) ([]byte, error)
- func DefaultDecompressReaderFunc(format string) (func(io.Reader) (io.Reader, error), error)
- func DelmSplitStrings(s, delm string, n uint) string
- func EncodeHash(b []byte) string
- func EnsureRead(ctx context.Context, r io.Reader, b []byte) (n uint64, _ error)
- func EnsureWrite(w io.Writer, b []byte) (int, error)
- func Filter2Slices[T any, Y any](a []T, b []Y, f func(T, Y) bool) []T
- func FilterMap[T any, Y comparable](s map[Y]T, f func(Y, T) bool) []T
- func FilterSlice[T any](s []T, f func(T) bool) []T
- func Float64ToBytes(i float64) []byte
- func FuncCaller(skip int) errors.Frame
- func Int64ToBigBytes(i int64) []byte
- func Int64ToBytes(i int64) []byte
- func IsDuplicatedSlice[T any](s []T, keyf func(T) (bool, string)) bool
- func IsDuplicatedSliceWithMap[T any](s []T, keyf func(T) (bool, string)) (map[string]T, bool)
- func IsEqualHashByter(a, b HashByter) bool
- func IsNilJSON(b []byte) bool
- func IsValidURL(u *url.URL) error
- func JoinErrors(errs ...error) error
- func LoadFromContext(ctx context.Context, a ...interface{}) error
- func LoadFromContextOK(ctx context.Context, a ...interface{}) error
- func MarshalJSON(v interface{}) ([]byte, error)
- func MarshalJSONIndent(i interface{}) ([]byte, error)
- func MustMarshalJSON(i interface{}) []byte
- func MustMarshalJSONIndent(i interface{}) []byte
- func MustMarshalJSONIndentString(i interface{}) string
- func MustMarshalJSONString(i interface{}) string
- func NewLengthedBytesSlice(m [][]byte) ([]byte, error)
- func NormalizeTime(t time.Time) time.Time
- func ParseDuration(s string) (time.Duration, error)
- func ParseRFC3339(s string) (time.Time, error)
- func PipeReadWrite(ctx context.Context, read func(context.Context, io.Reader) error, ...) error
- func RFC3339(t time.Time) string
- func RandomChoiceSlice[T any](a []T, size int64) ([]T, error)
- func ReadLength(r io.Reader) (read uint64, length uint64, _ error)
- func ReadLengthBytes(b []byte) (uint64, error)
- func ReadLengthed(r io.Reader) (read uint64, _ []byte, _ error)
- func ReadLengthedBytes(b []byte) (_ []byte, left []byte, _ error)
- func ReadLengthedBytesSlice(b []byte) (m [][]byte, left []byte, _ error)
- func ReadLengthedSlice(r io.Reader) (read uint64, hs [][]byte, _ error)
- func ReflectPtrSetInterfaceValue[T any](v interface{}, t *T) error
- func ReflectSetInterfaceValue(v, target interface{}) error
- func RemoveDuplicatedSlice[T any](s []T, f func(T) (string, error)) ([]T, error)
- func Retry(ctx context.Context, f func() (bool, error), limit int, interval time.Duration) error
- func RunErrCallbackJobWorker(ctx context.Context, workersize, size int64, errf func(error), ...) error
- func RunJobWorker(ctx context.Context, workersize, size int64, ...) error
- func RunJobWorkerByJobs(ctx context.Context, jobs ...ContextWorkerCallback) error
- func SHA256Checksum(b []byte) string
- func SetInterfaceValue[T any](v interface{}, t *T) error
- func SingleflightDo[T any](sg *singleflight.Group, key string, f func() (T, error)) (t T, _ error, _ bool)
- func SortCompactAppendSlice[T any](size int, less func(T, T) bool) (add func(T) bool, done func() []T)
- func StringError(format string, args ...interface{}) *baseError
- func TimeEqual(a, b time.Time) bool
- func TimeString(t time.Time) string
- func TraverseSlice[T any](s []T, f func(int, T) error) error
- func ULID() ulid.ULID
- func UUID() uuid.UUID
- func Uint64ToBigBytes(i uint64) []byte
- func Uint64ToBytes(i uint64) []byte
- func Uint8ToBytes(i uint8) []byte
- func UintToBytes(i uint) []byte
- func UniqCompactAppendSlice[T cmp.Ordered](size int) (add func(T), done func() []T)
- func UnmarshalJSON(b []byte, v interface{}) error
- func UnmarshalWithYAMLOrderedMap(b []byte) (interface{}, error)
- func UnmarshalYAMLNodeWithYAMLOrderedMap(y *yaml.Node) (interface{}, error)
- func WriteLength(w io.Writer, i uint64) error
- func WriteLengthed(w io.Writer, b []byte) error
- func WriteLengthedSlice(w io.Writer, m [][]byte) error
- func ZerologMarshalStack(err error) interface{}
- type BaseGCache
- func (c *BaseGCache[K, V]) Close()
- func (c *BaseGCache[K, V]) Exists(key K) bool
- func (c *BaseGCache[K, V]) Get(key K) (v V, found bool)
- func (c *BaseGCache[K, V]) Purge()
- func (c *BaseGCache[K, V]) Remove(key K) bool
- func (c *BaseGCache[K, V]) Set(key K, v V, expire time.Duration)
- func (c *BaseGCache[K, V]) Traverse(f func(K, V) bool)
- type BaseJobWorker
- type BaseParams
- func (p *BaseParams) ID() string
- func (p *BaseParams) IsValid([]byte) error
- func (p *BaseParams) Set(f func() (bool, error)) error
- func (p *BaseParams) SetDuration(d time.Duration, f func(time.Duration) (bool, error)) error
- func (p *BaseParams) SetInt(d int, f func(int) (bool, error)) error
- func (p *BaseParams) SetOverZeroInt(d int, f func(int) (bool, error)) error
- func (p *BaseParams) SetUint64(d uint64, f func(uint64) (bool, error)) error
- type BufferedResetReader
- type BufferedWriter
- type BuildInfo
- type Byter
- type BytesFrameReader
- func (f *BytesFrameReader) Body() ([]byte, error)
- func (f *BytesFrameReader) BodyReader() (io.Reader, error)
- func (f *BytesFrameReader) Header() ([][]byte, error)
- func (f *BytesFrameReader) Lengthed(read func([]byte) error) error
- func (f *BytesFrameReader) Reader() io.Reader
- func (f *BytesFrameReader) Version() [2]byte
- type BytesFrameWriter
- type BytesToByter
- type ChecksumReader
- type ChecksumWriter
- type CompressedReader
- type ContextDaemon
- type ContextKey
- type ContextWorkerCallback
- type Daemon
- type DecompressReaderFunc
- type DefaultExtensibleJSON
- type DummyByter
- type DummyChecksumWriter
- type DummyIsValider
- type ExtensibleJSON
- type ExtensibleJSONSetter
- type FuncChain
- type GCache
- type GzipWriter
- type Hash
- type HashByter
- type HashChecksumReader
- type HashChecksumWriter
- type Hasher
- type IDError
- func (er IDError) Error() string
- func (er *IDError) Errorf(format string, args ...interface{}) *IDError
- func (er IDError) Format(st fmt.State, verb rune)
- func (er *IDError) Is(err error) bool
- func (er IDError) StackTrace() errors.StackTrace
- func (er IDError) Unwrap() error
- func (er *IDError) WithMessage(err error, format string, args ...interface{}) error
- func (er *IDError) WithStack() *IDError
- func (er *IDError) Wrap(err error) error
- type IsValider
- type JobWorker
- type Locked
- func (l *Locked[T]) Empty(f func(_ T, isempty bool) error) error
- func (l *Locked[T]) EmptyValue() *Locked[T]
- func (l *Locked[T]) Get(f func(T, bool) error) error
- func (l *Locked[T]) GetOrCreate(f func(_ T, created bool) error, create func() (T, error)) error
- func (l *Locked[T]) MustValue() (v T)
- func (l *Locked[T]) Set(f func(_ T, isempty bool) (T, error)) (v T, _ error)
- func (l *Locked[T]) SetValue(v T) *Locked[T]
- func (l *Locked[T]) Value() (v T, isempty bool)
- type LockedMap
- type PurgeFuncGCache
- type ReadableDuration
- type SafeGzipReadCloser
- type ShardedMap
- func NewDeepShardedMap[K cmp.Ordered, V any](sizes []uint64, newMap func() LockedMap[K, V]) (*ShardedMap[K, V], error)
- func NewShardedMap[K cmp.Ordered, V any](size uint64, newMap func() LockedMap[K, V]) (*ShardedMap[K, V], error)
- func NewShardedMapWithSeed[K cmp.Ordered, V any](seed uint32, size uint64, ...) (*ShardedMap[K, V], error)
- func (l *ShardedMap[K, V]) Close()
- func (l *ShardedMap[K, V]) Empty()
- func (l *ShardedMap[K, V]) Exists(k K) bool
- func (l *ShardedMap[K, V]) Get(key K, f func(value V, found bool) error) error
- func (l *ShardedMap[K, V]) GetOrCreate(k K, f func(_ V, created bool) error, create func() (V, error)) error
- func (l *ShardedMap[K, V]) Len() int
- func (l *ShardedMap[K, V]) Map() (m map[K]V)
- func (l *ShardedMap[K, V]) Remove(k K, f func(V, bool) error) (bool, error)
- func (l *ShardedMap[K, V]) RemoveValue(k K) bool
- func (l *ShardedMap[K, V]) Set(k K, f func(V, bool) (V, error)) (v V, created bool, _ error)
- func (l *ShardedMap[K, V]) SetOrRemove(k K, f func(V, bool) (V, bool, error)) (v V, _ bool, _ bool, _ error)
- func (l *ShardedMap[K, V]) SetValue(k K, v V) (added bool)
- func (l *ShardedMap[K, V]) Traverse(f func(K, V) bool) bool
- func (l *ShardedMap[K, V]) TraverseMap(f func(LockedMap[K, V]) bool) bool
- func (l *ShardedMap[K, V]) Value(k K) (v V, found bool)
- type SimpleTimer
- type SimpleTimers
- func (ts *SimpleTimers) New(id TimerID, intervalFunc func(uint64) time.Duration, ...) (bool, error)
- func (ts *SimpleTimers) NewTimer(timer *SimpleTimer) (bool, error)
- func (ts *SimpleTimers) Stop() error
- func (ts *SimpleTimers) StopAllTimers() error
- func (ts *SimpleTimers) StopOthers(exclude []TimerID) error
- func (ts *SimpleTimers) StopTimers(ids []TimerID) error
- type SingleLockedMap
- func (l *SingleLockedMap[K, V]) Close()
- func (l *SingleLockedMap[K, V]) Empty()
- func (l *SingleLockedMap[K, V]) Exists(k K) bool
- func (l *SingleLockedMap[K, V]) Get(key K, f func(value V, found bool) error) error
- func (l *SingleLockedMap[K, V]) GetOrCreate(k K, f func(_ V, created bool) error, create func() (V, error)) error
- func (l *SingleLockedMap[K, V]) Len() int
- func (l *SingleLockedMap[K, V]) Map() (m map[K]V)
- func (l *SingleLockedMap[K, V]) Remove(k K, f func(V, bool) error) (bool, error)
- func (l *SingleLockedMap[K, V]) RemoveValue(k K) bool
- func (l *SingleLockedMap[K, V]) Set(k K, f func(_ V, found bool) (V, error)) (v V, created bool, _ error)
- func (l *SingleLockedMap[K, V]) SetOrRemove(k K, f func(V, bool) (v V, _ bool, _ error)) (v V, _ bool, _ bool, _ error)
- func (l *SingleLockedMap[K, V]) SetValue(k K, v V) (added bool)
- func (l *SingleLockedMap[K, V]) Traverse(f func(K, V) bool) bool
- func (l *SingleLockedMap[K, V]) Value(k K) (v V, found bool)
- type StreamDecoder
- type StreamEncoder
- type Stringer
- type TimerID
- type ULIDPool
- type Version
- func (v Version) Compare(b Version) int
- func (v Version) IsCompatible(b Version) bool
- func (v Version) IsEmpty() bool
- func (v Version) IsValid([]byte) error
- func (v Version) Major() uint64
- func (v Version) MarshalText() ([]byte, error)
- func (v Version) Minor() uint64
- func (v Version) Patch() uint64
- func (v Version) Prerelease() string
- func (v Version) String() string
- func (v *Version) UnmarshalText(b []byte) error
- type YAMLOrderedMap
- func (m *YAMLOrderedMap) Clear()
- func (m *YAMLOrderedMap) Delete(k string) (removed bool)
- func (m *YAMLOrderedMap) Get(k string) (_ interface{}, found bool)
- func (m *YAMLOrderedMap) Len() int
- func (m *YAMLOrderedMap) MarshalYAML() (interface{}, error)
- func (m *YAMLOrderedMap) Set(k string, v interface{}) (isnew bool)
- func (m *YAMLOrderedMap) Traverse(f func(k string, v interface{}) bool)
- func (m *YAMLOrderedMap) UnmarshalYAML(y *yaml.Node) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrDaemonAlreadyStarted = NewIDError("daemon already started") ErrDaemonAlreadyStopped = NewIDError("daemon already stopped") )
var ( ErrFound = NewIDError("found") ErrNotFound = NewIDError("not found") ErrDuplicated = NewIDError("duplicated") ErrNotImplemented = NewIDError("not implemented") ErrInternal = NewIDError("internal error") )
var ( ErrLockedSetIgnore = NewIDError("ignore to set locked value") ErrLockedMapClosed = NewIDError("locked map closed") )
var EmptyCancelFunc = func() error { return nil }
var ErrInvalid = NewIDError("invalid")
var ErrJobWorkerDone = NewIDError("job worker: no more new job")
var MinVersionLength = 2
var (
ULIDLen = len([]byte(ULID().String()))
)
Functions ¶
func AssertInterfaceValue ¶
func AwareContextValue ¶
func BatchWork ¶
func BatchWork( ctx context.Context, size, limit int64, 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 BoolToBytes ¶
func BytesToInt64 ¶
func BytesToUint64 ¶
func CheckIsValiderSlice ¶
func CompactAppendSlice ¶
func ConcatByterSlice ¶
func ConcatByters ¶
func ConcatBytesSlice ¶
func ContextWithValues ¶
func ContextWithValues(ctx context.Context, v map[ContextKey]interface{}) context.Context
func CountFilteredSlice ¶
func DecodeHash ¶
func DelmSplitStrings ¶
func EncodeHash ¶
func Filter2Slices ¶
func FilterMap ¶
func FilterMap[T any, Y comparable](s map[Y]T, f func(Y, T) bool) []T
func FilterSlice ¶
func Float64ToBytes ¶
func FuncCaller ¶
func Int64ToBigBytes ¶
func Int64ToBytes ¶
func IsEqualHashByter ¶
func IsValidURL ¶
func JoinErrors ¶
func LoadFromContext ¶
func LoadFromContextOK ¶
func MarshalJSON ¶
func MarshalJSONIndent ¶
func MustMarshalJSON ¶
func MustMarshalJSON(i interface{}) []byte
func MustMarshalJSONIndent ¶
func MustMarshalJSONIndent(i interface{}) []byte
func MustMarshalJSONIndentString ¶
func MustMarshalJSONIndentString(i interface{}) string
func MustMarshalJSONString ¶
func MustMarshalJSONString(i interface{}) string
func NewLengthedBytesSlice ¶
func NormalizeTime ¶
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 ParseRFC3339 ¶
ParseRFC3339 parses RFC3339 string.
func PipeReadWrite ¶
func RandomChoiceSlice ¶
RandomChoiceSlice creates new n-sized slice randomly.
func ReadLengthBytes ¶
func ReadLengthedBytesSlice ¶
func ReflectSetInterfaceValue ¶
func ReflectSetInterfaceValue(v, target interface{}) error
func RemoveDuplicatedSlice ¶
func RunErrCallbackJobWorker ¶
func RunJobWorker ¶
func RunJobWorkerByJobs ¶
func RunJobWorkerByJobs(ctx context.Context, jobs ...ContextWorkerCallback) error
func SHA256Checksum ¶
func SetInterfaceValue ¶
func SingleflightDo ¶
func SortCompactAppendSlice ¶
func StringError ¶
func StringError(format string, args ...interface{}) *baseError
func TimeString ¶
func Uint64ToBigBytes ¶
func Uint64ToBytes ¶
func Uint8ToBytes ¶
func UintToBytes ¶
func UniqCompactAppendSlice ¶
func UnmarshalJSON ¶
func UnmarshalYAMLNodeWithYAMLOrderedMap ¶
func UnmarshalYAMLNodeWithYAMLOrderedMap(y *yaml.Node) (interface{}, error)
func ZerologMarshalStack ¶
func ZerologMarshalStack(err error) interface{}
Types ¶
type BaseGCache ¶
func NewLFUGCache ¶
func NewLFUGCache[K cmp.Ordered, V any](size int) *BaseGCache[K, V]
func NewLRUGCache ¶
func NewLRUGCache[K cmp.Ordered, V any](size int) *BaseGCache[K, V]
func (*BaseGCache[K, V]) Close ¶
func (c *BaseGCache[K, V]) Close()
func (*BaseGCache[K, V]) Exists ¶
func (c *BaseGCache[K, V]) Exists(key K) bool
func (*BaseGCache[K, V]) Get ¶
func (c *BaseGCache[K, V]) Get(key K) (v V, found bool)
func (*BaseGCache[K, V]) Purge ¶
func (c *BaseGCache[K, V]) Purge()
func (*BaseGCache[K, V]) Remove ¶
func (c *BaseGCache[K, V]) Remove(key K) bool
func (*BaseGCache[K, V]) Set ¶
func (c *BaseGCache[K, V]) Set(key K, v V, expire time.Duration)
func (*BaseGCache[K, V]) Traverse ¶
func (c *BaseGCache[K, V]) Traverse(f func(K, V) bool)
type BaseJobWorker ¶
type BaseJobWorker struct { NewJobFunc func(jobCount uint64, _ ContextWorkerCallback) error // contains filtered or unexported fields }
func NewBaseJobWorker ¶
func NewBaseJobWorker(ctx context.Context, semSize int64) (*BaseJobWorker, error)
func NewErrCallbackJobWorker ¶
func NewErrCallbackJobWorker(ctx context.Context, semSize int64, errf func(error)) (wk *BaseJobWorker, _ error)
NewErrCallbackJobWorker ignores job error.
func (*BaseJobWorker) Cancel ¶
func (wk *BaseJobWorker) Cancel()
func (*BaseJobWorker) Close ¶
func (wk *BaseJobWorker) Close()
func (*BaseJobWorker) Done ¶
func (wk *BaseJobWorker) Done()
func (*BaseJobWorker) LazyWait ¶
func (wk *BaseJobWorker) LazyWait() error
LazyWait don't wait until all job finished.
func (*BaseJobWorker) NewJob ¶
func (wk *BaseJobWorker) NewJob(c ContextWorkerCallback) error
func (*BaseJobWorker) Wait ¶
func (wk *BaseJobWorker) Wait() error
Wait waits until all job finished.
type BaseParams ¶
func NewBaseParams ¶
func NewBaseParams() *BaseParams
func (*BaseParams) ID ¶
func (p *BaseParams) ID() string
func (*BaseParams) IsValid ¶
func (p *BaseParams) IsValid([]byte) error
func (*BaseParams) SetDuration ¶
func (*BaseParams) SetOverZeroInt ¶
type BufferedResetReader ¶
type BufferedResetReader struct { io.Reader sync.RWMutex // contains filtered or unexported fields }
func NewBufferedResetReader ¶
func NewBufferedResetReader(r io.Reader) *BufferedResetReader
func (*BufferedResetReader) Close ¶
func (s *BufferedResetReader) Close() error
func (*BufferedResetReader) Reset ¶
func (s *BufferedResetReader) Reset()
type BufferedWriter ¶
func NewBufferedWriter ¶
func NewBufferedWriter(w io.Writer, size int) *BufferedWriter
func (*BufferedWriter) Close ¶
func (w *BufferedWriter) Close() error
type BuildInfo ¶
func ParseBuildInfo ¶
type BytesFrameReader ¶
type BytesFrameReader struct {
// contains filtered or unexported fields
}
func NewBufferBytesFrameReader ¶
func NewBufferBytesFrameReader(b []byte) (*BytesFrameReader, *bytes.Buffer, error)
func NewBufferBytesNoHeadersFrameReader ¶
func NewBufferBytesNoHeadersFrameReader(b []byte) (*BytesFrameReader, *bytes.Buffer, error)
func NewBytesFrameReader ¶
func NewBytesFrameReader(r io.Reader) (*BytesFrameReader, error)
func (*BytesFrameReader) Body ¶
func (f *BytesFrameReader) Body() ([]byte, error)
func (*BytesFrameReader) BodyReader ¶
func (f *BytesFrameReader) BodyReader() (io.Reader, error)
func (*BytesFrameReader) Header ¶
func (f *BytesFrameReader) Header() ([][]byte, error)
func (*BytesFrameReader) Lengthed ¶
func (f *BytesFrameReader) Lengthed(read func([]byte) error) error
func (*BytesFrameReader) Reader ¶
func (f *BytesFrameReader) Reader() io.Reader
func (*BytesFrameReader) Version ¶
func (f *BytesFrameReader) Version() [2]byte
type BytesFrameWriter ¶
type BytesFrameWriter struct {
// contains filtered or unexported fields
}
func NewBufferBytesFrameWriter ¶
func NewBufferBytesFrameWriter() (*BytesFrameWriter, *bytes.Buffer)
func NewBytesFrameWriter ¶
func NewBytesFrameWriter(w io.Writer) (*BytesFrameWriter, error)
func (*BytesFrameWriter) Header ¶
func (f *BytesFrameWriter) Header(bs ...[]byte) error
func (*BytesFrameWriter) Lengthed ¶
func (f *BytesFrameWriter) Lengthed(b []byte) error
Lengthed writes bytes body with length. Lengthed can be used multiple times.
func (*BytesFrameWriter) Writer ¶
func (f *BytesFrameWriter) Writer() io.Writer
Writer returns io.Writer. Writer is for not lengthed body.
type BytesToByter ¶
type BytesToByter []byte
func (BytesToByter) Bytes ¶
func (b BytesToByter) Bytes() []byte
type ChecksumWriter ¶
type ChecksumWriter interface { io.WriteCloser Name() string Checksum() string }
type CompressedReader ¶
type CompressedReader struct { io.Reader Format string // NOTE compress format, usually file extension without '.' prefix sync.RWMutex // contains filtered or unexported fields }
func NewCompressedReader ¶
func NewCompressedReader( r io.Reader, format string, decompressReader DecompressReaderFunc, ) (*CompressedReader, error)
func (*CompressedReader) Close ¶
func (r *CompressedReader) Close() error
Close only closes decompress Reader.
func (*CompressedReader) Decompress ¶
func (r *CompressedReader) Decompress() (io.Reader, error)
func (*CompressedReader) Exaust ¶
func (r *CompressedReader) Exaust() error
Exaust read all unread bytes from Decompress().
type ContextDaemon ¶
func NewContextDaemon ¶
func NewContextDaemon(startfunc func(context.Context) error) *ContextDaemon
func (*ContextDaemon) IsStarted ¶
func (dm *ContextDaemon) IsStarted() bool
func (*ContextDaemon) Stop ¶
func (dm *ContextDaemon) Stop() error
type ContextKey ¶
type ContextKey string
type ContextWorkerCallback ¶
type DecompressReaderFunc ¶
type DefaultExtensibleJSON ¶
type DefaultExtensibleJSON struct {
// contains filtered or unexported fields
}
func (DefaultExtensibleJSON) MarshaledJSON ¶
func (e DefaultExtensibleJSON) MarshaledJSON() ([]byte, bool)
func (*DefaultExtensibleJSON) SetMarshaledJSON ¶
func (e *DefaultExtensibleJSON) SetMarshaledJSON(b []byte)
type DummyByter ¶
type DummyByter func() []byte
func (DummyByter) Bytes ¶
func (d DummyByter) Bytes() []byte
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 ¶
func (DummyIsValider) IsValid ¶
func (iv DummyIsValider) IsValid(b []byte) error
type ExtensibleJSON ¶
type ExtensibleJSONSetter ¶
type ExtensibleJSONSetter interface {
SetMarshaledJSON([]byte)
}
type FuncChain ¶
type FuncChain struct {
// contains filtered or unexported fields
}
func NewFuncChain ¶
func NewFuncChain() *FuncChain
type GzipWriter ¶
GzipWriter closes the underlying reader too.
func NewGzipWriter ¶
func NewGzipWriter(f io.Writer, level int) (*GzipWriter, error)
func (*GzipWriter) Close ¶
func (w *GzipWriter) Close() error
type HashByter ¶
type HashByter interface { // HashBytes is uses to generate hash HashBytes() []byte }
type HashChecksumReader ¶
func NewHashChecksumReader ¶
func NewHashChecksumReader(r io.Reader, h hash.Hash) *HashChecksumReader
func (*HashChecksumReader) Checksum ¶
func (r *HashChecksumReader) Checksum() string
func (*HashChecksumReader) Close ¶
func (r *HashChecksumReader) Close() error
type HashChecksumWriter ¶
func NewHashChecksumWriter ¶
func NewHashChecksumWriter(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
type IDError ¶
type IDError struct {
// contains filtered or unexported fields
}
func NewBaseIDErrorWithID ¶
func NewIDError ¶
func NewIDErrorWithID ¶
func (IDError) StackTrace ¶
func (er IDError) StackTrace() errors.StackTrace
func (*IDError) WithMessage ¶
WithMessage formats strings with error.
type JobWorker ¶
type JobWorker interface { NewJob(ContextWorkerCallback) error Done() Wait() error Close() }
type Locked ¶
func EmptyLocked ¶
func (*Locked[T]) EmptyValue ¶
func (*Locked[T]) GetOrCreate ¶
type LockedMap ¶
type LockedMap[K cmp.Ordered, V any] interface { Exists(key K) (found bool) Value(key K) (value V, found bool) SetValue(key K, value V) (added bool) RemoveValue(key K) (removed bool) Get(key K, f func(value V, found bool) error) error GetOrCreate(key K, f func(value V, created bool) error, create func() (value V, _ error)) error Set(key K, f func(_ V, found bool) (value V, _ error)) (value V, created bool, _ error) Remove(key K, f func(value V, found bool) error) (removed bool, _ error) SetOrRemove(key K, f func(_ V, found bool) (value V, remove bool, _ error)) (_ V, created, removed bool, _ error) Traverse(f func(key K, value V) (keep bool)) bool Len() int Empty() Close() Map() map[K]V }
type PurgeFuncGCache ¶
type PurgeFuncGCache[K cmp.Ordered, V any] struct { GCache[K, V] // contains filtered or unexported fields }
func NewPurgeFuncGCache ¶
func (*PurgeFuncGCache[K, V]) Purge ¶
func (c *PurgeFuncGCache[K, V]) Purge()
type ReadableDuration ¶
func (ReadableDuration) MarshalText ¶
func (d ReadableDuration) MarshalText() ([]byte, error)
func (*ReadableDuration) UnmarshalJSON ¶
func (d *ReadableDuration) UnmarshalJSON(b []byte) error
func (*ReadableDuration) UnmarshalYAML ¶
func (d *ReadableDuration) UnmarshalYAML(y *yaml.Node) error
type SafeGzipReadCloser ¶
SafeGzipReadCloser closes the underlying reader too.
func NewSafeGzipReadCloser ¶
func NewSafeGzipReadCloser(f io.Reader) (*SafeGzipReadCloser, error)
func (*SafeGzipReadCloser) Close ¶
func (r *SafeGzipReadCloser) Close() error
type ShardedMap ¶
type ShardedMap[K cmp.Ordered, V any] struct { sync.RWMutex // contains filtered or unexported fields }
func NewDeepShardedMap ¶
func NewShardedMap ¶
func NewShardedMapWithSeed ¶
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(key K, f func(value V, found bool) error) error
func (*ShardedMap[K, V]) GetOrCreate ¶
func (l *ShardedMap[K, V]) GetOrCreate( k K, f func(_ V, created bool) error, create func() (V, error), ) error
func (*ShardedMap[K, V]) Len ¶
func (l *ShardedMap[K, V]) Len() int
func (*ShardedMap[K, V]) Map ¶
func (l *ShardedMap[K, V]) Map() (m map[K]V)
func (*ShardedMap[K, V]) Remove ¶
func (l *ShardedMap[K, V]) Remove(k K, f func(V, bool) 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, created bool, _ error)
func (*ShardedMap[K, V]) SetOrRemove ¶
func (*ShardedMap[K, V]) SetValue ¶
func (l *ShardedMap[K, V]) SetValue(k K, v V) (added bool)
func (*ShardedMap[K, V]) Traverse ¶
func (l *ShardedMap[K, V]) Traverse(f func(K, V) bool) bool
func (*ShardedMap[K, V]) TraverseMap ¶
func (l *ShardedMap[K, V]) TraverseMap(f func(LockedMap[K, V]) bool) bool
func (*ShardedMap[K, V]) Value ¶
func (l *ShardedMap[K, V]) Value(k K) (v V, found bool)
type SimpleTimer ¶
type SimpleTimers ¶
type SimpleTimers struct { *ContextDaemon // contains filtered or unexported fields }
SimpleTimers handles the multiple schdduled jobs without many goroutines.
func NewSimpleTimers ¶
func NewSimpleTimers(size uint64, resolution time.Duration) (*SimpleTimers, error)
func NewSimpleTimersFixedIDs ¶
func (*SimpleTimers) NewTimer ¶
func (ts *SimpleTimers) NewTimer(timer *SimpleTimer) (bool, error)
func (*SimpleTimers) Stop ¶
func (ts *SimpleTimers) Stop() error
func (*SimpleTimers) StopAllTimers ¶
func (ts *SimpleTimers) StopAllTimers() error
func (*SimpleTimers) StopOthers ¶
func (ts *SimpleTimers) StopOthers(exclude []TimerID) error
StopOthers stops timers except exclude timers.
func (*SimpleTimers) StopTimers ¶
func (ts *SimpleTimers) StopTimers(ids []TimerID) error
type SingleLockedMap ¶
type SingleLockedMap[K cmp.Ordered, V any] struct { sync.RWMutex // contains filtered or unexported fields }
func NewSingleLockedMap ¶
func NewSingleLockedMap[K cmp.Ordered, V any]() *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(key K, f func(value V, found bool) error) error
func (*SingleLockedMap[K, V]) GetOrCreate ¶
func (l *SingleLockedMap[K, V]) GetOrCreate( k K, f func(_ V, created bool) error, create func() (V, error), ) error
func (*SingleLockedMap[K, V]) Len ¶
func (l *SingleLockedMap[K, V]) Len() int
func (*SingleLockedMap[K, V]) Map ¶
func (l *SingleLockedMap[K, V]) Map() (m map[K]V)
func (*SingleLockedMap[K, V]) Remove ¶
func (l *SingleLockedMap[K, V]) Remove(k K, f func(V, bool) 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 V, created bool, _ error)
func (*SingleLockedMap[K, V]) SetOrRemove ¶
func (*SingleLockedMap[K, V]) SetValue ¶
func (l *SingleLockedMap[K, V]) SetValue(k K, v V) (added bool)
func (*SingleLockedMap[K, V]) Traverse ¶
func (l *SingleLockedMap[K, V]) Traverse(f func(K, V) bool) 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 ULIDPool ¶
func NewULIDPool ¶
func NewULIDPool() *ULIDPool
type Version ¶
type Version struct {
// contains filtered or unexported fields
}
func EnsureParseVersion ¶
EnsureParseVersion tries to parse version string, but skips to check IsValid().
func MustNewVersion ¶
func ParseVersion ¶
ParseVersion tries to parse version string and also checks IsValid().
func (Version) IsCompatible ¶
IsCompatible checks if the given version is compatible to the target. The compatible conditions are major matches.
func (Version) MarshalText ¶
func (Version) Prerelease ¶
func (*Version) UnmarshalText ¶
type YAMLOrderedMap ¶
type YAMLOrderedMap struct {
// contains filtered or unexported fields
}
func NewYAMLOrderedMap ¶
func NewYAMLOrderedMap() *YAMLOrderedMap
func (*YAMLOrderedMap) Clear ¶
func (m *YAMLOrderedMap) Clear()
func (*YAMLOrderedMap) Delete ¶
func (m *YAMLOrderedMap) Delete(k string) (removed bool)
func (*YAMLOrderedMap) Get ¶
func (m *YAMLOrderedMap) Get(k string) (_ interface{}, found bool)
func (*YAMLOrderedMap) Len ¶
func (m *YAMLOrderedMap) Len() int
func (*YAMLOrderedMap) MarshalYAML ¶
func (m *YAMLOrderedMap) MarshalYAML() (interface{}, error)
func (*YAMLOrderedMap) Set ¶
func (m *YAMLOrderedMap) Set(k string, v interface{}) (isnew bool)
func (*YAMLOrderedMap) Traverse ¶
func (m *YAMLOrderedMap) Traverse(f func(k string, v interface{}) bool)
func (*YAMLOrderedMap) UnmarshalYAML ¶
func (m *YAMLOrderedMap) UnmarshalYAML(y *yaml.Node) error
Source Files ¶
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. |