Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
55 lines (47 sloc) 1.61 KB
// Copyright 2019, Chef. All rights reserved.
// https://github.com/q191201771/naza
//
// Use of this source code is governed by a MIT-style license
// that can be found in the License file.
//
// Author: Chef (191201771@qq.com)
// Package bininfo
// 将编译时源码的 git 版本信息(当前 commit log 的 sha 值和 commit message),编译时间,Go 版本,平台打入程序中
// 编译时传入这些信息的方式见 naza 的编译脚本: https://github.com/q191201771/naza/blob/master/build.sh
package bininfo
import (
"fmt"
"runtime"
"strings"
)
var (
// 初始化为 unknown,如果编译时没有传入这些值,则为 unknown
GitCommitLog = "unknown"
GitStatus = "unknown"
BuildTime = "unknown"
BuildGoVersion = "unknown"
)
// 返回单行格式
func StringifySingleLine() string {
return fmt.Sprintf("GitCommitLog=%s. GitStatus=%s. BuildTime=%s. GoVersion=%s. runtime=%s/%s.",
GitCommitLog, GitStatus, BuildTime, BuildGoVersion, runtime.GOOS, runtime.GOARCH)
}
// 返回多行格式
func StringifyMultiLine() string {
return fmt.Sprintf("GitCommitLog=%s\nGitStatus=%s\nBuildTime=%s\nGoVersion=%s\nruntime=%s/%s\n",
GitCommitLog, GitStatus, BuildTime, BuildGoVersion, runtime.GOOS, runtime.GOARCH)
}
// 对一些值做美化处理
func beauty() {
if GitStatus == "" {
// GitStatus 为空时,说明本地源码与最近的 commit 记录一致,无修改
// 为它赋一个特殊值
GitStatus = "cleanly"
} else {
// 将多行结果合并为一行
GitStatus = strings.Replace(strings.Replace(GitStatus, "\r\n", " |", -1), "\n", " |", -1)
}
}
func init() {
beauty()
}
You can’t perform that action at this time.