goinfo

package
v0.6.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 11 Imported by: 1

README

GoInfo

goutil/goinfo provide some useful info for golang.

Github: https://github.com/gookit/goutil

Install

go get github.com/gookit/goutil/goinfo

Go docs

Usage

gover := goinfo.GoVersion() // eg: "1.15.6"

Testings

go test -v ./goinfo/...

Test limit by regexp:

go test -v -run ^TestSetByKeys ./goinfo/...

Documentation

Overview

Package goinfo provide some standard util functions for go.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefStackLen = 10000
	MaxStackLen = 100000
)

some commonly consts

Functions

func CutFuncName

func CutFuncName(fullFcName string) (pkgPath, shortFnName string)

CutFuncName get pkg path and short func name eg:

"github.com/gookit/goutil/goinfo.FuncName" => [github.com/gookit/goutil/goinfo, FuncName]

func FuncName

func FuncName(fn any) string

FuncName get full func name, contains pkg path.

eg:

// OUTPUT: github.com/gookit/goutil/goinfo.PkgName
goinfo.FuncName(goinfo.PkgName)

func GetCallStacks

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

func GetCallerInfo(skip int) string

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

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

func GoVersion() string

GoVersion get go runtime version. eg: "1.18.2"

func GoodFuncName added in v0.6.13

func GoodFuncName(name string) bool

GoodFuncName reports whether the function name is a valid identifier.

func PkgName

func PkgName(fullFcName string) string

PkgName get current package name

Usage:

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

func SimpleCallersInfo

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.

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) Parse

func (ffn *FullFcName) Parse()

Parse the full func name.

func (*FullFcName) PkgName

func (ffn *FullFcName) PkgName() string

PkgName string get. eg: goinfo

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

type GoInfo struct {
	Version string
	GoOS    string
	Arch    string
}

GoInfo define

On os by:

go env GOVERSION GOOS GOARCH
go version // "go version go1.19 darwin/amd64"

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 := sysutil.ExecLine("go version")
	if err != nil {
		return err
	}

	info, err := goinfo.ParseGoVersion()
 	dump.P(info)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL