Skip to content

Import path: gitlab.soludian.com/soludian/fountain/libs/base/goinfo

goinfo

go
import "gitlab.soludian.com/soludian/fountain/libs/base/goinfo"

Package goinfo provide some standard util functions for go.

Index

Variables

some commonly consts

go
var (
    DefStackLen = 10000
    MaxStackLen = 100000
)

func CutFuncName

go
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

go
func FuncName(fn any) string

FuncName get full func name, contains pkg path.

eg:

output: gitlab.soludian.com/soludian/fountain/libs/base/goinfo.PkgName
goinfo.FuncName(goinfo.PkgName)

func GetCallStacks

go
func GetCallStacks(all bool) []byte

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

go
func GetCallerInfo(skip int) string

GetCallerInfo get caller func name and with base filename and line.

returns:

gitlab.soludian.com/soludian/fountain/libs/base/goinfo_test.someFunc2(),stack_test.go:26

func GetCallersInfo

go
func GetCallersInfo(skip, max int) []string

GetCallersInfo returns an array of strings containing the func name, file and line number of each stack frame leading.

NOTICE: max should > skip

func GoVersion

go
func GoVersion() string

GoVersion get go runtime version. eg: "1.18.2"

func PkgName

go
func PkgName(fullFcName string) string

PkgName get current package name

Usage:

fullFcName := goinfo.FuncName(fn)
pgkName := goinfo.PkgName(fullFcName)

func SimpleCallersInfo

go
func SimpleCallersInfo(skip, num int) []string

SimpleCallersInfo returns an array of strings containing the func name, file and line number of each stack frame leading.

type FullFcName

FullFcName struct.

go
type FullFcName struct {
    // FullName eg: gitlab.soludian.com/soludian/fountain/libs/base/goinfo.PanicIf
    FullName string
    // contains filtered or unexported fields
}

func (*FullFcName) FuncName

go
func (ffn *FullFcName) FuncName() string

FuncName get short func name. eg: PanicIf

func (*FullFcName) Parse

go
func (ffn *FullFcName) Parse()

Parse the full func name.

func (*FullFcName) PkgName

go
func (ffn *FullFcName) PkgName() string

PkgName string get. eg: goinfo

func (*FullFcName) PkgPath

go
func (ffn *FullFcName) PkgPath() string

PkgPath string get. eg: gitlab.soludian.com/soludian/fountain/libs/base/goinfo

func (*FullFcName) String

go
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"
go
type GoInfo struct {
    Version string
    GoOS    string
    Arch    string
}

func OsGoInfo

go
func OsGoInfo() (*GoInfo, error)

OsGoInfo fetch and parse

func ParseGoVersion

go
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