util

package
v0.0.0-...-5a6e01e Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: GPL-3.0 Imports: 35 Imported by: 0

Documentation

Overview

Package util provides tiny featured funcs.

Index

Constants

This section is empty.

Variables

View Source
var (
	DaemonAlreadyStartedError = NewError("daemon already started")
	DaemonAlreadyStoppedError = NewError("daemon already stopped")
)
View Source
var (
	IgnoreError     = NewError("ignore")
	NotFoundError   = NewError("not found")
	FoundError      = NewError("found")
	DuplicatedError = NewError("duplicated error")
	WrongTypeError  = NewError("wrong type")
	EmptyError      = NewError("empty")
)
View Source
var (
	InvalidVersionError       = NewError("invalid version found")
	VersionNotCompatibleError = NewError("versions not compatible")
)
View Source
var ContextValueNotFoundError = NewError("not found in context")
View Source
var InvalidUnsignedIntError = NewError("invalid UnsignedInt")
View Source
var JSON = jsoniter.Config{
	EscapeHTML:             true,
	SortMapKeys:            false,
	ValidateJsonRawMessage: false,
}.Froze()
View Source
var StopRetryingError = NewError("stop retrying")
View Source
var ZeroInt = big.NewInt(0)

Functions

func BoolToBytes

func BoolToBytes(b bool) []byte

func BytesToBool

func BytesToBool(b []byte) (bool, error)

func BytesToFloat64

func BytesToFloat64(b []byte) float64

func BytesToInt

func BytesToInt(b []byte) (int, error)

func BytesToInt64

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

func BytesToUint64

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

func BytesToUint8

func BytesToUint8(b []byte) (uint8, error)

func CheckPort

func CheckPort(proto string, addr string, timeout time.Duration) error

func ConcatBytesSlice

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

func CopyBytes

func CopyBytes(b []byte) []byte

func DurationToBytes

func DurationToBytes(d time.Duration) []byte

func EnsureErrors

func EnsureErrors(
	ctx context.Context,
	dur time.Duration,
	f func() error,
	errs ...error,
) error

func Float64ToBytes

func Float64ToBytes(i float64) []byte

func FreePort

func FreePort(proto string) (int, error)

func GenerateChecksum

func GenerateChecksum(i io.Reader) (string, error)

func GenerateED25519Privatekey

func GenerateED25519Privatekey() (ed25519.PrivateKey, error)

func GenerateFileChecksum

func GenerateFileChecksum(p string) (string, error)

func GenerateTLSCerts

func GenerateTLSCerts(host string, key ed25519.PrivateKey) ([]tls.Certificate, error)

func GenerateTLSCertsPair

func GenerateTLSCertsPair(host string, key ed25519.PrivateKey) (*pem.Block, *pem.Block, error)

func InStringSlice

func InStringSlice(n string, s []string) bool

func Int64ToBytes

func Int64ToBytes(i int64) []byte

func IntToBytes

func IntToBytes(i int) []byte

func InterfaceSetValue

func InterfaceSetValue(v, target interface{}) error

func LoadFromContextValue

func LoadFromContextValue(ctx context.Context, key ContextKey, target interface{}) error

func ParseBoolInQuery

func ParseBoolInQuery(s string) bool

func Readlines

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

func Retry

func Retry(max uint, interval time.Duration, callback func(int) error) error

func ShellExec

func ShellExec(ctx context.Context, c string) ([]byte, error)

func ULID

func ULID() ulid.ULID

func ULIDBytes

func ULIDBytes() []byte

func UUID

func UUID() uuid.UUID

func Uint64ToBytes

func Uint64ToBytes(i uint64) []byte

func Uint8ToBytes

func Uint8ToBytes(i uint8) []byte

func UintToBytes

func UintToBytes(i uint) []byte

func Writeline

func Writeline(w io.Writer, get func() ([]byte, error)) error

func WritelineAsync

func WritelineAsync(w io.Writer, get func() ([]byte, error), limit int64) error

Types

type BSONFilter

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

func EmptyBSONFilter

func EmptyBSONFilter() *BSONFilter

func NewBSONFilter

func NewBSONFilter(key string, value interface{}) *BSONFilter

func NewBSONFilterFromD

func NewBSONFilterFromD(d bson.D) *BSONFilter

func (*BSONFilter) Add

func (ft *BSONFilter) Add(key string, value interface{}) *BSONFilter

func (*BSONFilter) AddOp

func (ft *BSONFilter) AddOp(key string, value interface{}, op string) *BSONFilter

func (*BSONFilter) D

func (ft *BSONFilter) D() bson.D

type BaseSemWorker

type BaseSemWorker struct {
	N          int64
	Sem        *semaphore.Weighted
	Ctx        context.Context
	Cancel     func()
	JobCount   uint64
	NewJobFunc func(context.Context, uint64, ContextWorkerCallback)
	// 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 Byter

type Byter interface {
	Bytes() []byte
}

func NewByter

func NewByter(b []byte) Byter

type Callbacker

type Callbacker interface {
	Callback() error
}

type Checker

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

func NewChecker

func NewChecker(name string, fns []CheckerFunc) Checker

func (Checker) Check

func (ck Checker) Check() error

type CheckerFunc

type CheckerFunc func() (bool, error)

type ContextDaemon

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

func NewContextDaemon

func NewContextDaemon(name string, startfunc func(context.Context) error) *ContextDaemon

func (*ContextDaemon) IsStarted

func (dm *ContextDaemon) IsStarted() bool

func (*ContextDaemon) Start

func (dm *ContextDaemon) Start() error

func (*ContextDaemon) StartWithContext

func (dm *ContextDaemon) StartWithContext(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 ContextWorkerCallback

type ContextWorkerCallback func(context.Context, uint64) error

type Daemon

type Daemon interface {
	Start() error
	Stop() error
}

type DataContainerError

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

func NewDataContainerError

func NewDataContainerError(d interface{}) DataContainerError

func (DataContainerError) Data

func (er DataContainerError) Data() interface{}

func (DataContainerError) Error

func (er DataContainerError) Error() string

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 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 FunctionDaemon

type FunctionDaemon struct {
	sync.RWMutex
	*logging.Logging
	// contains filtered or unexported fields
}

func NewFunctionDaemon

func NewFunctionDaemon(fn func(chan struct{}) error, isDebug bool) *FunctionDaemon

func (*FunctionDaemon) IsStarted

func (dm *FunctionDaemon) IsStarted() bool

func (*FunctionDaemon) IsStopped

func (dm *FunctionDaemon) IsStopped() bool

func (*FunctionDaemon) SetBlocking

func (dm *FunctionDaemon) SetBlocking(blocked bool) *FunctionDaemon

func (*FunctionDaemon) Start

func (dm *FunctionDaemon) Start() error

func (*FunctionDaemon) Stop

func (dm *FunctionDaemon) Stop() error

type GzipReader

type GzipReader struct {
	*gzip.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

type GzipWriter

type GzipWriter struct {
	sync.Mutex
	*gzip.Writer
	// 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 Initializer

type Initializer interface {
	Initialize() error
}

type LockedItem

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

func NewLockedItem

func NewLockedItem(defaultValue interface{}) *LockedItem

func (*LockedItem) Set

func (li *LockedItem) Set(value interface{}) *LockedItem

func (*LockedItem) Value

func (li *LockedItem) Value() interface{}

type NError

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

func NewError

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

func (*NError) As

func (*NError) As(err interface{}) bool

func (*NError) Call

func (er *NError) Call() *NError

func (*NError) Caller

func (er *NError) Caller(n int) *NError

func (*NError) Error

func (er *NError) Error() string

func (*NError) Errorf

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

func (*NError) Format

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

func (*NError) Is

func (er *NError) Is(err error) bool

func (*NError) Merge

func (er *NError) Merge(err error) *NError

func (*NError) StackTrace

func (er *NError) StackTrace() errors.StackTrace

func (*NError) Unwrap

func (er *NError) Unwrap() error

func (*NError) Wrap

func (er *NError) Wrap(err error) *NError

type NilReadCloser

type NilReadCloser struct {
	io.Reader
}

func NewNilReadCloser

func NewNilReadCloser(r io.Reader) NilReadCloser

func (NilReadCloser) Close

func (NilReadCloser) Close() error

type ParallelWorker

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

func NewParallelWorker

func NewParallelWorker(name string, 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 UnsignedBigInt

type UnsignedBigInt struct {
	*big.Int
}

func NewUnsignedInt

func NewUnsignedInt(i int64) (UnsignedBigInt, error)

func NewUnsignedIntFromBigInt

func NewUnsignedIntFromBigInt(b *big.Int) (UnsignedBigInt, error)

func NewUnsignedIntFromString

func NewUnsignedIntFromString(s string) (UnsignedBigInt, error)

func (UnsignedBigInt) BigInt

func (us UnsignedBigInt) BigInt() *big.Int

func (*UnsignedBigInt) IsValid

func (us *UnsignedBigInt) IsValid() error

type Version

type Version string

func (Version) Bytes

func (vs Version) Bytes() []byte

func (Version) GO

func (vs Version) GO() string

GO returns golang style semver string. It does not check IsValid().

func (Version) IsCompatible

func (vs Version) IsCompatible(check Version) error

IsCompatible checks if the check version is compatible to the target. The compatible conditions are, - major matches - minor of the check version is same or lower than target - patch of the check version is same or lower than target

func (Version) IsValid

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

func (Version) String

func (vs Version) String() string

type WorkerCallback

type WorkerCallback func(uint, interface{}) error

Directories

Path Synopsis
Package cache provides caching.
Package cache provides caching.
Package encoder will replace encoder package with new design :(
Package encoder will replace encoder package with new design :(
bson
Package bsonenc support encoding and decoding instance by bson.
Package bsonenc support encoding and decoding instance by bson.
json
Package jsonenc support encoding and decoding instance by json.
Package jsonenc support encoding and decoding instance by json.
Package hint provides to handle struct and data with type and it's version.
Package hint provides to handle struct and data with type and it's version.
Package isvalid is valid.
Package isvalid is valid.
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 tree provides tree structures.
Package tree provides tree structures.
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