Refactor(debug): simplify version string (#380)

This commit is contained in:
Jason Lyu
2024-07-21 20:34:24 -04:00
committed by GitHub
parent dd791e50c1
commit 24b8cdd96b
3 changed files with 1 additions and 22 deletions

View File

@@ -1,7 +0,0 @@
//go:build debug
package version
func init() {
_debug = true
}

View File

@@ -9,8 +9,6 @@ import (
const Name = "tun2socks" const Name = "tun2socks"
var ( var (
_debug = false
// Version can be set at link time by executing // Version can be set at link time by executing
// the command: `git describe --abbrev=0 --tags HEAD` // the command: `git describe --abbrev=0 --tags HEAD`
Version string Version string
@@ -20,19 +18,8 @@ var (
GitCommit string GitCommit string
) )
func versionize(s string) string {
return strings.TrimPrefix(s, "v")
}
func Debug() bool {
return _debug
}
func String() string { func String() string {
if !Debug() { return fmt.Sprintf("%s-%s", Name, strings.TrimPrefix(Version, "v"))
return fmt.Sprintf("%s-%s", Name, versionize(Version))
}
return fmt.Sprintf("%s-%s (debug)", Name, versionize(Version))
} }
func BuildString() string { func BuildString() string {

View File

@@ -210,7 +210,6 @@ func version(w http.ResponseWriter, r *http.Request) {
render.JSON(w, r, render.M{ render.JSON(w, r, render.M{
"version": V.Version, "version": V.Version,
"commit": V.GitCommit, "commit": V.GitCommit,
"debug": V.Debug(),
"modules": V.Info(), "modules": V.Info(),
}) })
} }