Documentation
¶
Overview ¶
Package stdutil provide some standard util functions for go.
Index ¶
- Variables
- func BaseTypeVal(val interface{}) (value interface{}, err error)
- func BaseTypeVal2(v reflect.Value) (value interface{}, err error)
- func CutFuncName(fullFcName string) (pkgPath, shortFnName string)
- func DiscardE(_ error)
- func FuncName(fn interface{}) 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 IsEmpty(v interface{}) bool
- func IsFunc(val interface{}) bool
- func IsNil(v interface{}) bool
- func MustString(v interface{}) string
- func PanicIf(err error)
- func PanicIfErr(err error)
- func Panicf(format string, v ...interface{})
- func PkgName(fullFcName string) string
- func SimpleCallersInfo(skip, num int) []string
- func ToString(v interface{}) string
- func TryString(v interface{}) (string, error)
- func ValueIsEmpty(v reflect.Value) booldeprecated
- func ValueLen(v reflect.Value) intdeprecated
- func WaitCloseSignals(closer io.Closer) error
- type FullFcName
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( DefStackLen = 10000 MaxStackLen = 100000 )
some commonly consts
var ErrConvertFail = errors.New("convert value type is failure")
ErrConvertFail error define
Functions ¶
func BaseTypeVal ¶ added in v0.5.2
func BaseTypeVal(val interface{}) (value interface{}, err error)
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 CutFuncName ¶ added in v0.5.0
CutFuncName get pkg path and short func name
func FuncName ¶ added in v0.4.2
func FuncName(fn interface{}) string
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 MustString ¶
func MustString(v interface{}) string
MustString convert value(basic type) to string, will panic on convert a complex type.
func Panicf ¶
func Panicf(format string, v ...interface{})
Panicf format panic message use fmt.Sprintf
func PkgName ¶ added in v0.4.2
PkgName get current package name
Usage:
fullFcName := stdutil.FuncName(fn) pgkName := stdutil.PkgName(fullFcName)
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 ToString ¶
func ToString(v interface{}) string
ToString always convert value to string, will ignore error
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.