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 ¶ added in v0.5.2
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 ¶ added in v0.5.2
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 ¶ added in v0.5.7
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 ¶ added in v0.5.7
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 ¶ added in v0.5.0
CutFuncName get pkg path and short func name
func FuncName ¶ added in v0.4.2
FuncName get full func name, contains pkg path.
eg:
// OUTPUT: github.com/gookit/goutil/stdutil.PanicIf stdutil.FuncName(stdutil.PkgName)
func GetCallStacks ¶ added in v0.4.2
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 ¶ added in v0.5.0
GetCallerInfo get caller func name and with base filename and line.
returns:
github.com/gookit/goutil/stdutil_test.someFunc2(),stack_test.go:26
func GetCallersInfo ¶ added in v0.4.2
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 ¶ added in v0.4.2
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 GoVersion ¶ added in v0.5.5
func GoVersion() string
GoVersion get go runtime version. eg: "1.18.2"
func IsContains ¶ added in v0.5.7
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 ¶ added in v0.5.7
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 ¶ added in v0.4.2
PkgName get current package name
Usage:
fullFcName := stdutil.FuncName(fn) pgkName := stdutil.PkgName(fullFcName)
func SignalHandler ¶ added in v0.6.0
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 ¶ added in v0.5.0
SimpleCallersInfo returns an array of strings containing the func name, file and line number of each stack frame leading.
func ValueIsEmpty
deprecated
added in
v0.5.2
func WaitCloseSignals ¶ added in v0.4.2
WaitCloseSignals for some huang program.
Types ¶
type FullFcName ¶ added in v0.5.0
type FullFcName struct { // FullName eg: github.com/gookit/goutil/stdutil.PanicIf FullName string // contains filtered or unexported fields }
FullFcName struct.
func (*FullFcName) FuncName ¶ added in v0.5.0
func (ffn *FullFcName) FuncName() string
FuncName get short func name. eg: PanicIf
func (*FullFcName) PkgName ¶ added in v0.5.0
func (ffn *FullFcName) PkgName() string
PkgName string get. eg: stdutil
func (*FullFcName) PkgPath ¶ added in v0.5.0
func (ffn *FullFcName) PkgPath() string
PkgPath string get. eg: github.com/gookit/goutil/stdutil
func (*FullFcName) String ¶ added in v0.5.0
func (ffn *FullFcName) String() string
String get full func name string.
type SignalError ¶ added in v0.6.0
SignalError is returned by the signal handler's execute function when it terminates due to a received signal.
func (SignalError) Error ¶ added in v0.6.0
func (e SignalError) Error() string
Error implements the error interface.