Browse Source

feat: fetch golang info from runtime

v1.x.x v1.0.1
dnomd343 2 years ago
parent
commit
2c6e14f3ee
  1. 3
      Dockerfile
  2. 8
      cmd/xproxy.go

3
Dockerfile

@ -35,8 +35,7 @@ FROM ${GOLANG_IMG} AS xproxy
COPY . /XProxy COPY . /XProxy
WORKDIR /XProxy WORKDIR /XProxy
RUN go mod download -x RUN go mod download -x
RUN env CGO_ENABLED=0 go build -v -o xproxy -trimpath \ RUN env CGO_ENABLED=0 go build -v -o xproxy -trimpath -ldflags "-s -w" ./cmd/ && mv ./xproxy /tmp/
-ldflags "-X 'main.goVersion=$(go version)' -s -w" ./cmd/ && mv ./xproxy /tmp/
FROM alpine:3.16 AS asset FROM alpine:3.16 AS asset
WORKDIR /tmp/ WORKDIR /tmp/

8
cmd/xproxy.go

@ -11,6 +11,7 @@ import (
"io" "io"
"os" "os"
"path" "path"
"runtime"
"strconv" "strconv"
) )
@ -22,7 +23,6 @@ var v6TProxyPort = 7289
var configDir = "/etc/xproxy" var configDir = "/etc/xproxy"
var assetFile = "/assets.tar.xz" var assetFile = "/assets.tar.xz"
var goVersion string
var subProcess []*process.Process var subProcess []*process.Process
var assetDir, exposeDir, configFile string var assetDir, exposeDir, configFile string
@ -53,8 +53,8 @@ func xproxyInit() {
isDebug := flag.Bool("debug", os.Getenv("DEBUG") == "true", "Enable debug mode") isDebug := flag.Bool("debug", os.Getenv("DEBUG") == "true", "Enable debug mode")
configName := flag.String("config", xproxyConfig, "Config file name") configName := flag.String("config", xproxyConfig, "Config file name")
flag.Parse() flag.Parse()
if *isVersion { if *isVersion { // show version info and exit
fmt.Printf("XProxy version %s (%s)\n", version, goVersion) // show version info and exit fmt.Printf("XProxy version %s (%s %s/%s)\n", version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
os.Exit(0) os.Exit(0)
} }
@ -96,7 +96,7 @@ func main() {
}() }()
xproxyInit() xproxyInit()
var settings config.Config 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) config.Load(configFile, &settings)
loadNetwork(&settings) loadNetwork(&settings)
loadProxy(&settings) loadProxy(&settings)

Loading…
Cancel
Save