refactor(version): 模块化版本信息
将版本信息从 app.go 移至独立的 version 包,便于多模块引用。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
d7e7b36048
commit
e05cf8a674
12
Makefile
12
Makefile
@ -15,12 +15,12 @@ CGO_DISABLE := CGO_ENABLED=0
|
|||||||
|
|
||||||
# 生产构建标志
|
# 生产构建标志
|
||||||
LDFLAGS := -ldflags "-s -w \
|
LDFLAGS := -ldflags "-s -w \
|
||||||
-X 'rua.plus/lolly/internal/app.Version=$(VERSION)' \
|
-X 'rua.plus/lolly/internal/version.Version=$(VERSION)' \
|
||||||
-X 'rua.plus/lolly/internal/app.GitCommit=$(GIT_COMMIT)' \
|
-X 'rua.plus/lolly/internal/version.GitCommit=$(GIT_COMMIT)' \
|
||||||
-X 'rua.plus/lolly/internal/app.GitBranch=$(GIT_BRANCH)' \
|
-X 'rua.plus/lolly/internal/version.GitBranch=$(GIT_BRANCH)' \
|
||||||
-X 'rua.plus/lolly/internal/app.BuildTime=$(BUILD_TIME)' \
|
-X 'rua.plus/lolly/internal/version.BuildTime=$(BUILD_TIME)' \
|
||||||
-X 'rua.plus/lolly/internal/app.GoVersion=$(GO_VERSION)' \
|
-X 'rua.plus/lolly/internal/version.GoVersion=$(GO_VERSION)' \
|
||||||
-X 'rua.plus/lolly/internal/app.BuildPlatform=$(BUILD_PLATFORM)'"
|
-X 'rua.plus/lolly/internal/version.BuildPlatform=$(BUILD_PLATFORM)'"
|
||||||
|
|
||||||
# 运行时性能优化标志
|
# 运行时性能优化标志
|
||||||
PERF_GCFLAGS := -gcflags="-l=4"
|
PERF_GCFLAGS := -gcflags="-l=4"
|
||||||
|
|||||||
@ -35,22 +35,7 @@ import (
|
|||||||
"rua.plus/lolly/internal/server"
|
"rua.plus/lolly/internal/server"
|
||||||
"rua.plus/lolly/internal/stream"
|
"rua.plus/lolly/internal/stream"
|
||||||
"rua.plus/lolly/internal/variable"
|
"rua.plus/lolly/internal/variable"
|
||||||
)
|
"rua.plus/lolly/internal/version"
|
||||||
|
|
||||||
// 版本信息,通过 -ldflags 注入。
|
|
||||||
var (
|
|
||||||
// Version 版本号
|
|
||||||
Version = "dev"
|
|
||||||
// GitCommit Git 提交哈希
|
|
||||||
GitCommit = "unknown"
|
|
||||||
// GitBranch Git 分支名
|
|
||||||
GitBranch = "unknown"
|
|
||||||
// BuildTime 构建时间
|
|
||||||
BuildTime = "unknown"
|
|
||||||
// GoVersion Go 版本
|
|
||||||
GoVersion = "unknown"
|
|
||||||
// BuildPlatform 构建平台
|
|
||||||
BuildPlatform = "unknown"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// App 应用程序结构。
|
// App 应用程序结构。
|
||||||
@ -146,11 +131,11 @@ func generateConfig(outputPath string) int {
|
|||||||
|
|
||||||
// printVersion 打印版本信息。
|
// printVersion 打印版本信息。
|
||||||
func printVersion() {
|
func printVersion() {
|
||||||
fmt.Printf("lolly version %s\n", Version)
|
fmt.Printf("lolly version %s\n", version.Version)
|
||||||
fmt.Printf(" Git: %s (%s)\n", GitCommit, GitBranch)
|
fmt.Printf(" Git: %s (%s)\n", version.GitCommit, version.GitBranch)
|
||||||
fmt.Printf(" Built: %s\n", BuildTime)
|
fmt.Printf(" Built: %s\n", version.BuildTime)
|
||||||
fmt.Printf(" Go: %s\n", GoVersion)
|
fmt.Printf(" Go: %s\n", version.GoVersion)
|
||||||
fmt.Printf(" Platform: %s\n", BuildPlatform)
|
fmt.Printf(" Platform: %s\n", version.BuildPlatform)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run 启动应用程序。
|
// Run 启动应用程序。
|
||||||
|
|||||||
@ -24,16 +24,7 @@ import (
|
|||||||
"rua.plus/lolly/internal/server"
|
"rua.plus/lolly/internal/server"
|
||||||
"rua.plus/lolly/internal/stream"
|
"rua.plus/lolly/internal/stream"
|
||||||
"rua.plus/lolly/internal/variable"
|
"rua.plus/lolly/internal/variable"
|
||||||
)
|
"rua.plus/lolly/internal/version"
|
||||||
|
|
||||||
// 版本信息,通过 -ldflags 注入。
|
|
||||||
var (
|
|
||||||
Version = "dev"
|
|
||||||
GitCommit = "unknown"
|
|
||||||
GitBranch = "unknown"
|
|
||||||
BuildTime = "unknown"
|
|
||||||
GoVersion = "unknown"
|
|
||||||
BuildPlatform = "unknown"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// App 应用程序结构(Windows 版本)。
|
// App 应用程序结构(Windows 版本)。
|
||||||
@ -121,11 +112,11 @@ func generateConfig(outputPath string) int {
|
|||||||
|
|
||||||
// printVersion 打印版本信息。
|
// printVersion 打印版本信息。
|
||||||
func printVersion() {
|
func printVersion() {
|
||||||
fmt.Printf("lolly version %s\n", Version)
|
fmt.Printf("lolly version %s\n", version.Version)
|
||||||
fmt.Printf(" Git: %s (%s)\n", GitCommit, GitBranch)
|
fmt.Printf(" Git: %s (%s)\n", version.GitCommit, version.GitBranch)
|
||||||
fmt.Printf(" Built: %s\n", BuildTime)
|
fmt.Printf(" Built: %s\n", version.BuildTime)
|
||||||
fmt.Printf(" Go: %s\n", GoVersion)
|
fmt.Printf(" Go: %s\n", version.GoVersion)
|
||||||
fmt.Printf(" Platform: %s\n", BuildPlatform)
|
fmt.Printf(" Platform: %s\n", version.BuildPlatform)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run 启动应用程序。
|
// Run 启动应用程序。
|
||||||
@ -341,7 +332,7 @@ func (a *App) reloadConfig() {
|
|||||||
// reopenLogs 重新打开日志文件(Windows stub)。
|
// reopenLogs 重新打开日志文件(Windows stub)。
|
||||||
func (a *App) reopenLogs() {
|
func (a *App) reopenLogs() {
|
||||||
if a.cfg != nil {
|
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 = logging.NewAppLogger(&a.cfg.Logging)
|
||||||
}
|
}
|
||||||
a.logger.LogStartup("日志已重新打开", nil)
|
a.logger.LogStartup("日志已重新打开", nil)
|
||||||
|
|||||||
20
internal/version/version.go
Normal file
20
internal/version/version.go
Normal 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"
|
||||||
|
)
|
||||||
Loading…
x
Reference in New Issue
Block a user