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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
// 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 ( )
}