Documentation ¶
Overview ¶
Package util provides tiny featured funcs.
Index ¶
- Variables
- func BoolToBytes(b bool) []byte
- func BytesToBool(b []byte) (bool, error)
- func BytesToFloat64(b []byte) float64
- func BytesToInt(b []byte) (int, error)
- func BytesToInt64(b []byte) (int64, error)
- func BytesToUint64(b []byte) (uint64, error)
- func BytesToUint8(b []byte) (uint8, error)
- func CheckPort(proto string, addr string, timeout time.Duration) error
- func ConcatBytesSlice(sl ...[]byte) []byte
- func CopyBytes(b []byte) []byte
- func DurationToBytes(d time.Duration) []byte
- func EnsureErrors(ctx context.Context, dur time.Duration, f func() error, errs ...error) error
- func Float64ToBytes(i float64) []byte
- func FreePort(proto string) (int, error)
- func GenerateChecksum(i io.Reader) (string, error)
- func GenerateED25519Privatekey() (ed25519.PrivateKey, error)
- func GenerateFileChecksum(p string) (string, error)
- func GenerateTLSCerts(host string, key ed25519.PrivateKey) ([]tls.Certificate, error)
- func GenerateTLSCertsPair(host string, key ed25519.PrivateKey) (*pem.Block, *pem.Block, error)
- func InStringSlice(n string, s []string) bool
- func Int64ToBytes(i int64) []byte
- func IntToBytes(i int) []byte
- func InterfaceSetValue(v, target interface{}) error
- func LoadFromContextValue(ctx context.Context, key ContextKey, target interface{}) error
- func ParseBoolInQuery(s string) bool
- func Readlines(r io.Reader, callback func([]byte) error) error
- func Retry(max uint, interval time.Duration, callback func(int) error) error
- func ShellExec(ctx context.Context, c string) ([]byte, error)
- func ULID() ulid.ULID
- func ULIDBytes() []byte
- func UUID() uuid.UUID
- func Uint64ToBytes(i uint64) []byte
- func Uint8ToBytes(i uint8) []byte
- func UintToBytes(i uint) []byte
- func Writeline(w io.Writer, get func() ([]byte, error)) error
- func WritelineAsync(w io.Writer, get func() ([]byte, error), limit int64) error
- type BSONFilter
- type BaseSemWorker
- func (wk *BaseSemWorker) Close()
- func (wk *BaseSemWorker) Done()
- func (wk *BaseSemWorker) Jobs() uint64
- func (wk *BaseSemWorker) LazyCancel(timeout time.Duration)
- func (wk *BaseSemWorker) NewJob(callback ContextWorkerCallback) error
- func (wk *BaseSemWorker) Wait() error
- func (wk *BaseSemWorker) WaitChan() chan error
- type Byter
- type Callbacker
- type Checker
- type CheckerFunc
- type ContextDaemon
- type ContextKey
- type ContextWorkerCallback
- type Daemon
- type DataContainerError
- type DistributeWorker
- type ErrgroupWorker
- type FunctionDaemon
- type GzipReader
- type GzipWriter
- type Initializer
- type LockedItem
- type NError
- func (*NError) As(err interface{}) bool
- func (er *NError) Call() *NError
- func (er *NError) Caller(n int) *NError
- func (er *NError) Error() string
- func (er *NError) Errorf(s string, a ...interface{}) *NError
- func (er *NError) Format(st fmt.State, verb rune)
- func (er *NError) Is(err error) bool
- func (er *NError) Merge(err error) *NError
- func (er *NError) StackTrace() errors.StackTrace
- func (er *NError) Unwrap() error
- func (er *NError) Wrap(err error) *NError
- type NilReadCloser
- type ParallelWorker
- func (wk *ParallelWorker) Done()
- func (wk *ParallelWorker) Errors() <-chan error
- func (wk *ParallelWorker) FinishedJobs() int
- func (wk *ParallelWorker) IsFinished() bool
- func (wk *ParallelWorker) Jobs() uint
- func (wk *ParallelWorker) NewJob(j interface{})
- func (wk *ParallelWorker) Run(callback WorkerCallback) *ParallelWorker
- type UnsignedBigInt
- type Version
- type WorkerCallback
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 BytesToBool ¶
func BytesToFloat64 ¶
func BytesToInt ¶
func BytesToInt64 ¶
func BytesToUint64 ¶
func BytesToUint8 ¶
func ConcatBytesSlice ¶
func DurationToBytes ¶
func EnsureErrors ¶
func Float64ToBytes ¶
func GenerateED25519Privatekey ¶
func GenerateED25519Privatekey() (ed25519.PrivateKey, error)
func GenerateFileChecksum ¶
func GenerateTLSCerts ¶
func GenerateTLSCerts(host string, key ed25519.PrivateKey) ([]tls.Certificate, error)
func GenerateTLSCertsPair ¶
func InStringSlice ¶
func Int64ToBytes ¶
func IntToBytes ¶
func InterfaceSetValue ¶
func InterfaceSetValue(v, target interface{}) error
func LoadFromContextValue ¶
func LoadFromContextValue(ctx context.Context, key ContextKey, target interface{}) error
func ParseBoolInQuery ¶
func Uint64ToBytes ¶
func Uint8ToBytes ¶
func UintToBytes ¶
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 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
type CheckerFunc ¶
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
type ContextKey ¶
type ContextKey string
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 ¶
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 ¶
GzipWriter closes the underlying reader too.
func NewGzipWriter ¶
func NewGzipWriter(f io.Writer) *GzipWriter
func (*GzipWriter) Close ¶
func (w *GzipWriter) Close() error
type Initializer ¶
type Initializer interface {
Initialize() error
}
type LockedItem ¶
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 (*NError) StackTrace ¶
func (er *NError) StackTrace() errors.StackTrace
type NilReadCloser ¶
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 ¶
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) IsCompatible ¶
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
type WorkerCallback ¶
Source Files ¶
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. |
Click to show internal directories.
Click to hide internal directories.