zutil

package
v1.7.12 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 19 Imported by: 26

Documentation

Overview

Package zutil daily development helper functions

Index

Constants

This section is empty.

Variables

View Source
var (
	BuffSize = bufTypes[3]
)

Functions

func BackOffDelay added in v1.6.2

func BackOffDelay(attempt int, maxRetryInterval time.Duration) time.Duration

func CheckErr deprecated

func CheckErr(err error, exit ...bool)

Deprecated: please use zerror.Panic CheckErr Check Err

func DoRetry added in v1.6.1

func DoRetry(sum int, fn func() bool, opt ...func(*RetryConf)) (ok bool)

DoRetry is a general retry function

func GOROOT added in v1.2.0

func GOROOT() string

func GetAllMethod added in v0.1.42

func GetAllMethod(s interface{}, fn func(numMethod int, m reflect.Method) error) error

GetAllMethod get all methods of struct

func GetBuff

func GetBuff(ss ...int) *bytes.Buffer

func GetGid added in v1.1.17

func GetGid() uint64

GetGid Get coroutine id

func GetOs added in v0.1.59

func GetOs() string

func GetParentProcessName added in v1.1.15

func GetParentProcessName() (string, error)

func Getenv added in v0.1.59

func Getenv(name string, def ...string) string

Getenv get ENV value by key name

func IfVal

func IfVal(condition bool, trueVal, falseVal interface{}) interface{}

IfVal Simulate ternary calculations, pay attention to handling no variables or indexing problems

func IsDoubleClickStartUp added in v1.1.15

func IsDoubleClickStartUp() bool

func IsLinux added in v0.1.59

func IsLinux() bool

IsLinux system

func IsMac added in v0.1.59

func IsMac() bool

IsMac system

func IsWin added in v0.1.59

func IsWin() bool

IsWin system. linux windows darwin

func MaxRlimit added in v1.1.21

func MaxRlimit() (int, error)

MaxRlimit tries to set the resource limit RLIMIT_NOFILE to the max (hard limit)

func Named added in v1.3.4

func Named(name string, arg interface{}) interface{}

Named creates a named argument

func Once added in v1.1.25

func Once[T any](fn func() T) func() T

Once initialize the singleton

func Optional added in v1.7.5

func Optional[T interface{}](o T, fn ...func(*T)) T

Optional Optional parameter

func PutBuff

func PutBuff(buffer *bytes.Buffer)

func ReflectForNumField

func ReflectForNumField(v reflect.Value, fn func(fieldName, fieldTag string,
	kind reflect.Kind, field reflect.Value) error, tag ...string) error

func ReflectStructField added in v0.1.43

func ReflectStructField(v reflect.Type, fn func(
	numField int, fieldTag string, field reflect.StructField) error, tag ...string) error

func RunAllMethod added in v0.0.26

func RunAllMethod(st interface{}, args ...interface{}) (err error)

RunAllMethod run all methods of struct

func RunAssignMethod added in v0.1.48

func RunAssignMethod(st interface{}, filter func(methodName string) bool, args ...interface{}) (err error)

RunAssignMethod run assign methods of struct

func SetValue

func SetValue(vTypeOf reflect.Kind, vValueOf reflect.Value, value interface{}) (err error)

func Try deprecated

func Try(fn func(), catch func(e interface{}), finally ...func())

Deprecated: please use zerror.TryCatch Try exception capture

func TryCatch added in v1.1.12

func TryCatch(fn func() error) (err error)

TryCatch exception capture

func UnescapeHTML added in v1.2.0

func UnescapeHTML(s string) string

func WithCompileHandler added in v1.3.4

func WithCompileHandler(fn ArgsCompileHandler) func(args *Args)

func WithOnlyNamed added in v1.3.4

func WithOnlyNamed() func(args *Args)

func WithRunContext added in v1.1.24

func WithRunContext(handler func()) (time.Duration, uint64)

WithRunContext function execution time and memory

Types

type Args added in v1.3.4

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

Args stores arguments associated

func NewArgs added in v1.3.4

func NewArgs(opt ...ArgsOpt) *Args

NewArgs returns a new Args

func (*Args) Compile added in v1.3.4

func (args *Args) Compile(format string, initialValue ...interface{}) (query string, values []interface{})

Compile compiles builder's format to standard sql and returns associated args

func (*Args) CompileArg added in v1.3.4

func (args *Args) CompileArg(buf *bytes.Buffer, values []interface{}, arg interface{}) []interface{}

func (*Args) CompileString added in v1.3.4

func (args *Args) CompileString(format string, initialValue ...interface{}) string

CompileString returns a string representation of Args

func (*Args) Var added in v1.6.4

func (args *Args) Var(arg interface{}) string

Var adds an arg to Args and returns a placeholder

type ArgsCompileHandler added in v1.3.4

type ArgsCompileHandler func(buf *bytes.Buffer, values []interface{}, arg interface{}) ([]interface{}, bool)

type ArgsOpt added in v1.3.4

type ArgsOpt func(*Args)

type Bool added in v1.3.0

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

func NewBool added in v1.3.0

func NewBool(b bool) *Bool

func (*Bool) CAS added in v1.3.0

func (b *Bool) CAS(old, new bool) bool

func (*Bool) Load added in v1.3.0

func (b *Bool) Load() bool

func (*Bool) Store added in v1.3.0

func (b *Bool) Store(val bool) bool

func (*Bool) Toggle added in v1.3.0

func (b *Bool) Toggle() (old bool)

type Chan added in v1.6.3

type Chan[T any] struct {
	// contains filtered or unexported fields
}

func NewChan added in v1.6.3

func NewChan[T any](cap ...int) *Chan[T]

func (*Chan[T]) Close added in v1.6.3

func (ch *Chan[T]) Close()

func (*Chan[T]) In added in v1.6.3

func (ch *Chan[T]) In() chan<- T

func (*Chan[T]) Len added in v1.6.3

func (ch *Chan[T]) Len() int

func (*Chan[T]) Out added in v1.6.3

func (ch *Chan[T]) Out() <-chan T

type Int32 added in v1.3.0

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

func NewInt32 added in v1.3.0

func NewInt32(i int32) *Int32

func (*Int32) Add added in v1.3.0

func (i32 *Int32) Add(i int32) int32

func (*Int32) CAS added in v1.3.0

func (i32 *Int32) CAS(old, new int32) bool

func (*Int32) Load added in v1.3.0

func (i32 *Int32) Load() int32

func (*Int32) Store added in v1.3.0

func (i32 *Int32) Store(i int32)

func (*Int32) String added in v1.3.0

func (i32 *Int32) String() string

func (*Int32) Sub added in v1.3.0

func (i32 *Int32) Sub(i int32) int32

func (*Int32) Swap added in v1.3.0

func (i32 *Int32) Swap(i int32) int32

type Int64 added in v1.3.2

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

func NewInt64 added in v1.3.2

func NewInt64(i int64) *Int64

func (*Int64) Add added in v1.3.2

func (i64 *Int64) Add(i int64) int64

func (*Int64) CAS added in v1.3.2

func (i64 *Int64) CAS(old, new int64) bool

func (*Int64) Load added in v1.3.2

func (i64 *Int64) Load() int64

func (*Int64) Store added in v1.3.2

func (i64 *Int64) Store(i int64)

func (*Int64) String added in v1.3.2

func (i64 *Int64) String() string

func (*Int64) Sub added in v1.3.2

func (i64 *Int64) Sub(i int64) int64

func (*Int64) Swap added in v1.3.2

func (i64 *Int64) Swap(i int64) int64

type Nocmp added in v1.3.0

type Nocmp [0]func()

Nocmp is an uncomparable struct

type Opt added in v1.6.3

type Opt func(*conf)

type Options added in v1.6.4

type Options struct {
	Cap int
}

type RetryConf added in v1.6.1

type RetryConf struct {

	// Interval is the interval between retries
	Interval time.Duration
	// MaxRetryInterval is the maximum interval between retries
	MaxRetryInterval time.Duration
	// Timeout is the timeout of the entire retry
	Timeout time.Duration
	// BackOffDelay is whether to increase the interval between retries
	BackOffDelay bool
	// contains filtered or unexported fields
}

type Stack added in v1.2.0

type Stack []uintptr

Stack uintptr array

func Callers added in v1.2.0

func Callers(skip ...int) Stack

func (Stack) Format added in v1.2.0

func (s Stack) Format(f func(fn *runtime.Func, file string, line int) bool)

type Uint32 added in v1.4.4

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

func NewUint32 added in v1.4.4

func NewUint32(i uint32) *Uint32

func (*Uint32) Add added in v1.4.4

func (u32 *Uint32) Add(i uint32) uint32

func (*Uint32) CAS added in v1.4.4

func (u32 *Uint32) CAS(old, new uint32) bool

func (*Uint32) Load added in v1.4.4

func (u32 *Uint32) Load() uint32

func (*Uint32) Store added in v1.4.4

func (u32 *Uint32) Store(i uint32)

func (*Uint32) String added in v1.4.4

func (u32 *Uint32) String() string

func (*Uint32) Sub added in v1.4.4

func (u32 *Uint32) Sub(i uint32) uint32

func (*Uint32) Swap added in v1.4.4

func (u32 *Uint32) Swap(i uint32) uint32

type Uint64 added in v1.6.3

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

func NewUint64 added in v1.6.3

func NewUint64(i uint64) *Uint64

func (*Uint64) Add added in v1.6.3

func (u64 *Uint64) Add(i uint64) uint64

func (*Uint64) CAS added in v1.6.3

func (u64 *Uint64) CAS(old, new uint64) bool

func (*Uint64) Load added in v1.6.3

func (u64 *Uint64) Load() uint64

func (*Uint64) Store added in v1.6.3

func (u64 *Uint64) Store(i uint64)

func (*Uint64) String added in v1.6.3

func (u64 *Uint64) String() string

func (*Uint64) Sub added in v1.6.3

func (u64 *Uint64) Sub(i uint64) uint64

func (*Uint64) Swap added in v1.6.3

func (u64 *Uint64) Swap(i uint64) uint64

type Uintptr added in v1.4.4

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

func NewUintptr added in v1.4.4

func NewUintptr(i uintptr) *Uintptr

func (*Uintptr) Add added in v1.4.4

func (ptr *Uintptr) Add(i uintptr) uintptr

func (*Uintptr) CAS added in v1.4.4

func (ptr *Uintptr) CAS(old, new uintptr) bool

func (*Uintptr) Load added in v1.4.4

func (ptr *Uintptr) Load() uintptr

func (*Uintptr) Store added in v1.4.4

func (ptr *Uintptr) Store(i uintptr)

func (*Uintptr) String added in v1.4.4

func (ptr *Uintptr) String() string

func (*Uintptr) Sub added in v1.4.4

func (ptr *Uintptr) Sub(i uintptr) uintptr

func (*Uintptr) Swap added in v1.4.4

func (ptr *Uintptr) Swap(i uintptr) uintptr

Directories

Path Synopsis
Package daemon program is installed as a system service to achieve process daemon
Package daemon program is installed as a system service to achieve process daemon

Jump to

Keyboard shortcuts

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