Skip to content

Commit 198c50e

Browse files
committed
core,tun2socks: prefer go1.24 style version
1 parent 4e9ed76 commit 198c50e

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

intra/core/version.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ package core
1010
import (
1111
"fmt"
1212
"runtime"
13+
"runtime/debug"
1314
)
1415

16+
var buildinfo, _ = debug.ReadBuildInfo()
17+
1518
var (
1619
// Commit set at link time by git rev-parse --short HEAD
1720
Commit string
@@ -20,5 +23,19 @@ var (
2023
)
2124

2225
func Version() string {
23-
return fmt.Sprintf("v%s-%s (%s/%s@%s)", Date, Commit, runtime.GOOS, runtime.GOARCH, runtime.Version())
26+
return fmt.Sprintf("%s (%s/%s@%s)", stamp(), runtime.GOOS, runtime.GOARCH, runtime.Version())
27+
}
28+
29+
func stamp() string {
30+
if buildinfo != nil {
31+
return buildinfo.Main.Path + "@v" + buildinfo.Main.Version
32+
}
33+
return Date + "-" + Commit
34+
}
35+
36+
func BuildInfo() string {
37+
if buildinfo == nil {
38+
return "unknown"
39+
}
40+
return buildinfo.String()
2441
}

intra/tun2socks.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ import (
3838
"github.com/celzero/firestack/intra/log"
3939
)
4040

41-
var buildinfo, _ = debug.ReadBuildInfo()
42-
4341
// pkg.go.dev/runtime#hdr-Environment_Variables
4442
type traceout string
4543

@@ -151,12 +149,11 @@ func Transparency(eim, eif bool) {
151149
}
152150

153151
// Build returns the build information.
154-
func Build(full bool) string {
155-
v := "unknown"
152+
func Build(full bool) (v string) {
156153
if !full {
157154
v = core.Version()
158-
} else if buildinfo != nil {
159-
v = buildinfo.String()
155+
} else {
156+
v = core.BuildInfo()
160157
}
161158
log.V("tun: build version %s", v)
162159
return v

0 commit comments

Comments
 (0)