Documentation ¶
Overview ¶
Package stdutil provide some standard util functions for go.
Index ¶
- Variables
- func BaseTypeVal(val any) (value any, err error)
- func BaseTypeVal2(v reflect.Value) (value any, err error)
- func CheckContains(data, elem any) (valid, found bool)
- func Contains(data, elem any) bool
- func CutFuncName(fullFcName string) (pkgPath, shortFnName string)
- func DiscardE(_ error)
- func FuncName(fn any) string
- func GetCallStacks(all bool) []byte
- func GetCallerInfo(skip int) string
- func GetCallersInfo(skip, max int) []string
- func Go(f func() error) error
- func GoVersion() string
- func IsContains(data, elem any) bool
- func IsEmpty(v any) bool
- func IsEqual(src, dst any) bool
- func IsFunc(val any) bool
- func IsNil(v any) bool
- func MustString(v any) string
- func PanicIf(err error)
- func PanicIfErr(err error)
- func Panicf(format string, v ...any)
- func PkgName(fullFcName string) string
- func SignalHandler(ctx context.Context, signals ...os.Signal) (execute func() error, interrupt func(error))
- func SimpleCallersInfo(skip, num int) []string
- func ToString(v any) string
- func TryString(v any) (string, error)
- func ValueIsEmpty(v reflect.Value) booldeprecated
- func ValueLen(v reflect.Value) intdeprecated
- func WaitCloseSignals(closer io.Closer) error
- type FullFcName
- type SignalError
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( DefStackLen = 10000 MaxStackLen = 100000 )
some commonly consts
Functions ¶
func BaseTypeVal ¶
BaseTypeVal convert custom type or intX,uintX,floatX to generic base type.
intX/unitX => int64 floatX => float64 string => string
returns int64,string,float or error
func BaseTypeVal2 ¶
BaseTypeVal2 convert custom type or intX,uintX,floatX to generic base type.
intX/unitX => int64 floatX => float64 string => string
returns int64,string,float or error
func CheckContains ¶
CheckContains try loop over the data check if the data includes the element.
TIP: only support types: string, map, array, slice
map - check key exists string - check sub-string exists array,slice - check sub-element exists
return (false, false) if impossible. return (true, false) if element was not found. return (true, true) if element was found.
func Contains ¶
Contains try loop over the data check if the data includes the element. alias of the IsContains
TIP: only support types: string, map, array, slice
map - check key exists string - check sub-string exists array,slice - check sub-element exists
func CutFuncName ¶
CutFuncName get pkg path and short func name
func FuncName ¶
FuncName get full func name, contains pkg path.
eg:
// OUTPUT: github.com/zhangyiming748/pretty/stdutil.PanicIf stdutil.FuncName(stdutil.PkgName)
func GetCallStacks ¶
GetCallStacks stacks is a wrapper for runtime. If all is true, Stack that attempts to recover the data for all goroutines.
from glog package
func GetCallerInfo ¶
GetCallerInfo get caller func name and with base filename and line.
returns:
github.com/zhangyiming748/pretty/stdutil_test.someFunc2(),stack_test.go:26
func GetCallersInfo ¶
GetCallersInfo returns an array of strings containing the func name, file and line number of each stack frame leading. NOTICE: max should > skip
func Go ¶
Go is a basic promise implementation: it wraps calls a function in a goroutine and returns a channel which will later return the function's return value.
func IsContains ¶
IsContains try loop over the data check if the data includes the element.
TIP: only support types: string, map, array, slice
map - check key exists string - check sub-string exists array,slice - check sub-element exists
func IsEqual ¶
IsEqual determines if two objects are considered equal.
TIP: cannot compare function type
func MustString ¶
MustString convert value(basic type) to string, will panic on convert a complex type.
func PkgName ¶
PkgName get current package name
Usage:
fullFcName := stdutil.FuncName(fn) pgkName := stdutil.PkgName(fullFcName)
func SignalHandler ¶
func SignalHandler(ctx context.Context, signals ...os.Signal) (execute func() error, interrupt func(error))
SignalHandler returns an actor, i.e. an execute and interrupt func, that terminates with SignalError when the process receives one of the provided signals, or the parent context is canceled.
func SimpleCallersInfo ¶
SimpleCallersInfo returns an array of strings containing the func name, file and line number of each stack frame leading.
func ValueIsEmpty
deprecated
func WaitCloseSignals ¶
WaitCloseSignals for some huang program.
Types ¶
type FullFcName ¶
type FullFcName struct { // FullName eg: github.com/zhangyiming748/pretty/stdutil.PanicIf FullName string // contains filtered or unexported fields }
FullFcName struct.
func (*FullFcName) FuncName ¶
func (ffn *FullFcName) FuncName() string
FuncName get short func name. eg: PanicIf
func (*FullFcName) PkgName ¶
func (ffn *FullFcName) PkgName() string
PkgName string get. eg: stdutil
func (*FullFcName) PkgPath ¶
func (ffn *FullFcName) PkgPath() string
PkgPath string get. eg: github.com/zhangyiming748/pretty/stdutil
func (*FullFcName) String ¶
func (ffn *FullFcName) String() string
String get full func name string.
type SignalError ¶
SignalError is returned by the signal handler's execute function when it terminates due to a received signal.
func (SignalError) Error ¶
func (e SignalError) Error() string
Error implements the error interface.