Files
go_blog/buildinfo/buildinfo.go
T

26 lines
763 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package buildinfo 保存编译时通过 -ldflags -X 注入的版本信息,
// 部署时由 install_linux.sh 注入 Git 提交哈希与编译时间。
package buildinfo
import "fmt"
// Commit 是编译时的 Git 短提交哈希(-X go_blog/buildinfo.Commit=<sha>)。
// 未注入时回退为 "dev"。
var Commit string
// BuildTime 是编译时间(UTC-X go_blog/buildinfo.BuildTime=<time>)。
// 未注入时回退为 "unknown"。
var BuildTime string
// String 返回展示用的版本字符串,如 "v443eccb · 2026-08-27T12:00:00Z"。
func String() string {
commit, buildTime := Commit, BuildTime
if commit == "" {
commit = "dev"
}
if buildTime == "" {
buildTime = "unknown"
}
return fmt.Sprintf("v%s · %s", commit, buildTime)
}