From 2c6e14f3ee41357b478a26eb16cb60dba80bc04c Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Fri, 9 Sep 2022 14:12:47 +0800 Subject: [PATCH] feat: fetch golang info from runtime --- Dockerfile | 3 +-- cmd/xproxy.go | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 35c151c..cfde329 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,8 +35,7 @@ FROM ${GOLANG_IMG} AS xproxy COPY . /XProxy WORKDIR /XProxy RUN go mod download -x -RUN env CGO_ENABLED=0 go build -v -o xproxy -trimpath \ - -ldflags "-X 'main.goVersion=$(go version)' -s -w" ./cmd/ && mv ./xproxy /tmp/ +RUN env CGO_ENABLED=0 go build -v -o xproxy -trimpath -ldflags "-s -w" ./cmd/ && mv ./xproxy /tmp/ FROM alpine:3.16 AS asset WORKDIR /tmp/ diff --git a/cmd/xproxy.go b/cmd/xproxy.go index c02e8f6..b0a7ca4 100644 --- a/cmd/xproxy.go +++ b/cmd/xproxy.go @@ -11,6 +11,7 @@ import ( "io" "os" "path" + "runtime" "strconv" ) @@ -22,7 +23,6 @@ var v6TProxyPort = 7289 var configDir = "/etc/xproxy" var assetFile = "/assets.tar.xz" -var goVersion string var subProcess []*process.Process var assetDir, exposeDir, configFile string @@ -53,8 +53,8 @@ func xproxyInit() { isDebug := flag.Bool("debug", os.Getenv("DEBUG") == "true", "Enable debug mode") configName := flag.String("config", xproxyConfig, "Config file name") flag.Parse() - if *isVersion { - fmt.Printf("XProxy version %s (%s)\n", version, goVersion) // show version info and exit + if *isVersion { // show version info and exit + fmt.Printf("XProxy version %s (%s %s/%s)\n", version, runtime.Version(), runtime.GOOS, runtime.GOARCH) os.Exit(0) } @@ -96,7 +96,7 @@ func main() { }() xproxyInit() var settings config.Config - log.Infof("XProxy %s start (%s)", version, goVersion) + log.Infof("XProxy %s start (%s %s/%s)", version, runtime.Version(), runtime.GOOS, runtime.GOARCH) config.Load(configFile, &settings) loadNetwork(&settings) loadProxy(&settings)