add gdebug.BuildInfo function; improving gproc

This commit is contained in:
John
2019-12-09 21:53:44 +08:00
parent 6ca5141020
commit 28825f5395
8 changed files with 64 additions and 22 deletions

View File

@ -10,6 +10,7 @@ package gdebug
import (
"bytes"
"fmt"
"github.com/gogf/gf"
"path/filepath"
"reflect"
"runtime"
@ -28,6 +29,9 @@ const (
)
var (
buildTime = "" // Binary time string, which is injected from "go build -ldflags '-X importpath.name=value'".
buildGoVersion = "" // Binary go version, which is injected from "go build -ldflags '-X importpath.name=value'".
buildGitCommit = "" // Binary git commit, which is injected from "go build -ldflags '-X importpath.name=value'".
goRootForFilter = runtime.GOROOT() // goRootForFilter is used for stack filtering purpose.
binaryVersion = "" // The version of current running binary(uint64 hex).
binaryVersionMd5 = "" // The version of current running binary(MD5).
@ -39,6 +43,18 @@ func init() {
}
}
// BuildInfo returns the built information of the binary.
// Note that it should be used with gf-cli tool: gf build,
// which injects necessary information into the binary.
func BuildInfo() map[string]string {
return map[string]string{
"gf": gf.VERSION,
"go": buildGoVersion,
"git": buildGitCommit,
"time": buildTime,
}
}
// BinVersion returns the version of current running binary.
// It uses ghash.BKDRHash+BASE36 algorithm to calculate the unique version of the binary.
func BinVersion() string {