Import path:
gitlab.soludian.com/soludian/fountain/libs/base/goinfo
goinfo
import "gitlab.soludian.com/soludian/fountain/libs/base/goinfo"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 PkgName(fullFcName string) string
- func SimpleCallersInfo(skip, num int) []string
- type FullFcName
- type GoInfo
Variables
var (
DefStackLen = 10000
MaxStackLen = 100000
)func CutFuncName
func CutFuncName(fullFcName string) (pkgPath, shortFnName string)CutFuncName get pkg path and short func name eg:
"gitlab.soludian.com/soludian/fountain/libs/base/goinfo.FuncName" => [gitlab.soludian.com/soludian/fountain/libs/base/goinfo, FuncName]func FuncName
func FuncName(fn any) stringFuncName get full func name, contains pkg path.
eg:
output: gitlab.soludian.com/soludian/fountain/libs/base/goinfo.PkgName
goinfo.FuncName(goinfo.PkgName)func GetCallStacks
func GetCallStacks(all bool) []byteGetCallStacks 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
func GetCallerInfo(skip int) stringGetCallerInfo get caller func name and with base filename and line.
returns:
gitlab.soludian.com/soludian/fountain/libs/base/goinfo_test.someFunc2(),stack_test.go:26func GetCallersInfo
func GetCallersInfo(skip, max int) []stringGetCallersInfo returns an array of strings containing the func name, file and line number of each stack frame leading.
NOTICE: max should > skip
func GoVersion
func GoVersion() stringGoVersion get go runtime version. eg: "1.18.2"
func PkgName
func PkgName(fullFcName string) stringPkgName get current package name
Usage:
fullFcName := goinfo.FuncName(fn)
pgkName := goinfo.PkgName(fullFcName)func SimpleCallersInfo
func SimpleCallersInfo(skip, num int) []stringSimpleCallersInfo returns an array of strings containing the func name, file and line number of each stack frame leading.
type FullFcName
FullFcName struct.
type FullFcName struct {
// FullName eg: gitlab.soludian.com/soludian/fountain/libs/base/goinfo.PanicIf
FullName string
// contains filtered or unexported fields
}func (*FullFcName) FuncName
func (ffn *FullFcName) FuncName() stringFuncName get short func name. eg: PanicIf
func (*FullFcName) Parse
func (ffn *FullFcName) Parse()Parse the full func name.
func (*FullFcName) PkgName
func (ffn *FullFcName) PkgName() stringPkgName string get. eg: goinfo
func (*FullFcName) PkgPath
func (ffn *FullFcName) PkgPath() stringPkgPath string get. eg: gitlab.soludian.com/soludian/fountain/libs/base/goinfo
func (*FullFcName) String
func (ffn *FullFcName) String() stringString 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"type GoInfo struct {
Version string
GoOS string
Arch string
}func OsGoInfo
func OsGoInfo() (*GoInfo, error)OsGoInfo fetch and parse
func ParseGoVersion
func ParseGoVersion(line string) (*GoInfo, error)ParseGoVersion get info by parse `go version` results.
Examples:
line, err := sys_util.ExecLine("go version")
if err != nil {
return err
}
info, err := goinfo.ParseGoVersion()
dump.P(info)Generated by gomarkdoc