mirror of https://github.com/q191201771/lal.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package bininfo
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
)
|
|
|
|
// 编译时通过如下方式传入编译时信息
|
|
// go build -ldflags " \
|
|
// -X 'github.com/q191201771/lal/pkg/util/bininfo.GitCommitID=`git log --pretty=format:'%h' -n 1`' \
|
|
// -X 'github.com/q191201771/lal/pkg/util/bininfo.BuildTime=`date +'%Y.%m.%d.%H%M%S'`' \
|
|
// -X 'github.com/q191201771/lal/pkg/util/bininfo.BuildGoVersion=`go version`' \
|
|
// "
|
|
|
|
var (
|
|
GitCommitID string
|
|
BuildTime string
|
|
BuildGoVersion string
|
|
)
|
|
|
|
func StringifySingleLine() string {
|
|
return fmt.Sprintf("GitCommitID=%s. BuildTime=%s. GoVersion=%s. runtime=%s/%s.",
|
|
GitCommitID, BuildTime, BuildGoVersion, runtime.GOOS, runtime.GOARCH)
|
|
}
|
|
|
|
func StringifyMultiLine() string {
|
|
return fmt.Sprintf("GitCommitID=%s\nBuildTime=%s\nGoVersion=%s\nruntime=%s/%s.",
|
|
GitCommitID, BuildTime, BuildGoVersion, runtime.GOOS, runtime.GOARCH)
|
|
}
|
|
|
|
func init() {
|
|
if GitCommitID == "" {
|
|
GitCommitID = "unknown"
|
|
}
|
|
if BuildTime == "" {
|
|
BuildTime = "unknown"
|
|
}
|
|
if BuildGoVersion == "" {
|
|
BuildGoVersion = "unknown"
|
|
}
|
|
}
|