Documentation ¶
Overview ¶
Package goinfo provide some standard util functions for go.
Index ¶
- Variables
- func CutFuncName(fullFcName string) (pkgPath, shortFnName string)
- func FuncName(fn any) string
- func GetCallStacks(all bool) []byte
- func GetCallerInfo(skip int) string
- func GetCallersInfo(skip, max int) []string
- func GoVersion() string
- func GoodFuncName(name string) bool
- func PkgName(fullFcName string) string
- func SimpleCallersInfo(skip, num int) []string
- type FullFcName
- type GoInfo
Constants ¶
This section is empty.
Variables ¶
var ( DefStackLen = 10000 MaxStackLen = 100000 )
some commonly consts
Functions ¶
func CutFuncName ¶
CutFuncName get pkg path and short func name eg:
"github.com/gookit/goutil/goinfo.FuncName" => [github.com/gookit/goutil/goinfo, FuncName]
func FuncName ¶
FuncName get full func name, contains pkg path.
eg:
// OUTPUT: github.com/gookit/goutil/goinfo.PkgName goinfo.FuncName(goinfo.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/gookit/goutil/goinfo_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 GoodFuncName ¶ added in v0.6.13
GoodFuncName reports whether the function name is a valid identifier.
func PkgName ¶
PkgName get current package name
Usage:
fullFcName := goinfo.FuncName(fn) pgkName := goinfo.PkgName(fullFcName)
func SimpleCallersInfo ¶
SimpleCallersInfo returns an array of strings containing the func name, file and line number of each stack frame leading.
Types ¶
type FullFcName ¶
type FullFcName struct { // FullName eg: "github.com/gookit/goutil/goinfo.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) PkgPath ¶
func (ffn *FullFcName) PkgPath() string
PkgPath string get. eg: github.com/gookit/goutil/goinfo
func (*FullFcName) String ¶
func (ffn *FullFcName) String() string
String get full func name string, pkg path and func name.
type GoInfo ¶
GoInfo define
On os by:
go env GOVERSION GOOS GOARCH go version // "go version go1.19 darwin/amd64"
func ParseGoVersion ¶
ParseGoVersion get info by parse `go version` results.
Examples:
line, err := sysutil.ExecLine("go version") if err != nil { return err } info, err := goinfo.ParseGoVersion() dump.P(info)