mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2024-12-30 02:37:01 +00:00
Refactor: standalone version module
This commit is contained in:
@@ -11,8 +11,8 @@ CGO_ENABLED := 0
|
||||
GO111MODULE := on
|
||||
|
||||
LDFLAGS += -w -s -buildid=
|
||||
LDFLAGS += -X "$(MODULE)/constant.Version=$(BUILD_VERSION)"
|
||||
LDFLAGS += -X "$(MODULE)/constant.GitCommit=$(BUILD_COMMIT)"
|
||||
LDFLAGS += -X "$(MODULE)/version.Version=$(BUILD_VERSION)"
|
||||
LDFLAGS += -X "$(MODULE)/version.GitCommit=$(BUILD_COMMIT)"
|
||||
|
||||
GO_BUILD = GO111MODULE=$(GO111MODULE) CGO_ENABLED=$(CGO_ENABLED) \
|
||||
go build $(BUILD_FLAGS) -ldflags '$(LDFLAGS)' -tags '$(BUILD_TAGS)' -trimpath
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
Name = "tun2socks"
|
||||
)
|
||||
|
||||
var (
|
||||
Version string
|
||||
GitCommit string
|
||||
)
|
||||
+4
-1
@@ -2,6 +2,7 @@ package engine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/v2/component/dialer"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"github.com/xjasonlyu/tun2socks/v2/proxy"
|
||||
"github.com/xjasonlyu/tun2socks/v2/stats"
|
||||
"github.com/xjasonlyu/tun2socks/v2/tunnel"
|
||||
"github.com/xjasonlyu/tun2socks/v2/version"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@@ -60,7 +62,8 @@ func (e *engine) start() error {
|
||||
}
|
||||
|
||||
if e.Version {
|
||||
showVersion()
|
||||
fmt.Println(version.String())
|
||||
fmt.Println(version.BuildString())
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
V "github.com/xjasonlyu/tun2socks/v2/constant"
|
||||
)
|
||||
|
||||
func showVersion() {
|
||||
fmt.Print(versionString())
|
||||
fmt.Print(releaseString())
|
||||
}
|
||||
|
||||
func versionString() string {
|
||||
return fmt.Sprintf("%s-%s\n", V.Name, strings.TrimPrefix(V.Version, "v"))
|
||||
}
|
||||
|
||||
func releaseString() string {
|
||||
return fmt.Sprintf("%s/%s, %s, %s\n", runtime.GOOS, runtime.GOARCH, runtime.Version(), V.GitCommit)
|
||||
}
|
||||
+1
-1
@@ -8,9 +8,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
V "github.com/xjasonlyu/tun2socks/v2/constant"
|
||||
"github.com/xjasonlyu/tun2socks/v2/log"
|
||||
"github.com/xjasonlyu/tun2socks/v2/tunnel/statistic"
|
||||
V "github.com/xjasonlyu/tun2socks/v2/version"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/cors"
|
||||
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const Name = "tun2socks"
|
||||
|
||||
var (
|
||||
// Version can be set at link time by executing
|
||||
// the command: `git describe --abbrev=0 --tags HEAD`
|
||||
Version string
|
||||
|
||||
// GitCommit can be set at link time by executing
|
||||
// the command: `git rev-parse --short HEAD`
|
||||
GitCommit string
|
||||
)
|
||||
|
||||
func String() string {
|
||||
return fmt.Sprintf("%s-%s", Name, strings.TrimPrefix(Version, "v"))
|
||||
}
|
||||
|
||||
func BuildString() string {
|
||||
return fmt.Sprintf("%s/%s, %s, %s", runtime.GOOS, runtime.GOARCH, runtime.Version(), GitCommit)
|
||||
}
|
||||
Reference in New Issue
Block a user