refactor(version): 模块化版本信息

将版本信息从 app.go 移至独立的 version 包,便于多模块引用。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
xfy 2026-04-20 18:07:21 +08:00
parent d7e7b36048
commit e05cf8a674
4 changed files with 39 additions and 43 deletions

View File

@ -15,12 +15,12 @@ CGO_DISABLE := CGO_ENABLED=0
# 生产构建标志
LDFLAGS := -ldflags "-s -w \
-X 'rua.plus/lolly/internal/app.Version=$(VERSION)' \
-X 'rua.plus/lolly/internal/app.GitCommit=$(GIT_COMMIT)' \
-X 'rua.plus/lolly/internal/app.GitBranch=$(GIT_BRANCH)' \
-X 'rua.plus/lolly/internal/app.BuildTime=$(BUILD_TIME)' \
-X 'rua.plus/lolly/internal/app.GoVersion=$(GO_VERSION)' \
-X 'rua.plus/lolly/internal/app.BuildPlatform=$(BUILD_PLATFORM)'"
-X 'rua.plus/lolly/internal/version.Version=$(VERSION)' \
-X 'rua.plus/lolly/internal/version.GitCommit=$(GIT_COMMIT)' \
-X 'rua.plus/lolly/internal/version.GitBranch=$(GIT_BRANCH)' \
-X 'rua.plus/lolly/internal/version.BuildTime=$(BUILD_TIME)' \
-X 'rua.plus/lolly/internal/version.GoVersion=$(GO_VERSION)' \
-X 'rua.plus/lolly/internal/version.BuildPlatform=$(BUILD_PLATFORM)'"
# 运行时性能优化标志
PERF_GCFLAGS := -gcflags="-l=4"

View File

@ -35,22 +35,7 @@ import (
"rua.plus/lolly/internal/server"
"rua.plus/lolly/internal/stream"
"rua.plus/lolly/internal/variable"
)
// 版本信息,通过 -ldflags 注入。
var (
// Version 版本号
Version = "dev"
// GitCommit Git 提交哈希
GitCommit = "unknown"
// GitBranch Git 分支名
GitBranch = "unknown"
// BuildTime 构建时间
BuildTime = "unknown"
// GoVersion Go 版本
GoVersion = "unknown"
// BuildPlatform 构建平台
BuildPlatform = "unknown"
"rua.plus/lolly/internal/version"
)
// App 应用程序结构。
@ -146,11 +131,11 @@ func generateConfig(outputPath string) int {
// printVersion 打印版本信息。
func printVersion() {
fmt.Printf("lolly version %s\n", Version)
fmt.Printf(" Git: %s (%s)\n", GitCommit, GitBranch)
fmt.Printf(" Built: %s\n", BuildTime)
fmt.Printf(" Go: %s\n", GoVersion)
fmt.Printf(" Platform: %s\n", BuildPlatform)
fmt.Printf("lolly version %s\n", version.Version)
fmt.Printf(" Git: %s (%s)\n", version.GitCommit, version.GitBranch)
fmt.Printf(" Built: %s\n", version.BuildTime)
fmt.Printf(" Go: %s\n", version.GoVersion)
fmt.Printf(" Platform: %s\n", version.BuildPlatform)
}
// Run 启动应用程序。

View File

@ -24,16 +24,7 @@ import (
"rua.plus/lolly/internal/server"
"rua.plus/lolly/internal/stream"
"rua.plus/lolly/internal/variable"
)
// 版本信息,通过 -ldflags 注入。
var (
Version = "dev"
GitCommit = "unknown"
GitBranch = "unknown"
BuildTime = "unknown"
GoVersion = "unknown"
BuildPlatform = "unknown"
"rua.plus/lolly/internal/version"
)
// App 应用程序结构Windows 版本)。
@ -121,11 +112,11 @@ func generateConfig(outputPath string) int {
// printVersion 打印版本信息。
func printVersion() {
fmt.Printf("lolly version %s\n", Version)
fmt.Printf(" Git: %s (%s)\n", GitCommit, GitBranch)
fmt.Printf(" Built: %s\n", BuildTime)
fmt.Printf(" Go: %s\n", GoVersion)
fmt.Printf(" Platform: %s\n", BuildPlatform)
fmt.Printf("lolly version %s\n", version.Version)
fmt.Printf(" Git: %s (%s)\n", version.GitCommit, version.GitBranch)
fmt.Printf(" Built: %s\n", version.BuildTime)
fmt.Printf(" Go: %s\n", version.GoVersion)
fmt.Printf(" Platform: %s\n", version.BuildPlatform)
}
// Run 启动应用程序。
@ -341,7 +332,7 @@ func (a *App) reloadConfig() {
// reopenLogs 重新打开日志文件Windows stub
func (a *App) reopenLogs() {
if a.cfg != nil {
logging.Init(a.cfg.Logging.Error.Level, false)
logging.Init(a.cfg.Logging.Error.Level, a.cfg.Logging.Format)
a.logger = logging.NewAppLogger(&a.cfg.Logging)
}
a.logger.LogStartup("日志已重新打开", nil)

View File

@ -0,0 +1,20 @@
// Package version 提供版本信息。
//
// 版本信息通过 -ldflags 在构建时注入。
package version
// 版本信息,通过 -ldflags 注入。
var (
// Version 版本号
Version = "dev"
// GitCommit Git 提交哈希
GitCommit = "unknown"
// GitBranch Git 分支名
GitBranch = "unknown"
// BuildTime 构建时间
BuildTime = "unknown"
// GoVersion Go 版本
GoVersion = "unknown"
// BuildPlatform 构建平台
BuildPlatform = "unknown"
)