From 165411a12b0c2d4285b9d4aa02743cd2ca43e530 Mon Sep 17 00:00:00 2001 From: naiba Date: Tue, 18 Jan 2022 20:41:51 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .goreleaser.yml | 2 ++ cmd/agent/main.go | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index 5a8c900..d8589b8 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -4,6 +4,8 @@ before: builds: - env: - CGO_ENABLED=0 + ldflags: + - -s -w -X main.version={{.Version}} -X main.arch={{.Arch}} goos: - linux - windows diff --git a/cmd/agent/main.go b/cmd/agent/main.go index 7ddd9f7..c75f9ab 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -11,6 +11,7 @@ import ( "net/http" "os" "os/exec" + "runtime" "time" "github.com/blang/semver" @@ -45,6 +46,7 @@ type AgentConfig struct { var ( version string + arch string = runtime.GOARCH client pb.NezhaServiceClient inited bool ) @@ -71,6 +73,10 @@ func init() { } func main() { + if arch != runtime.GOARCH { + panic(fmt.Sprintf("与当前系统不匹配,当前运行 %s_%s, 需要下载 %s_%s", runtime.GOOS, arch, runtime.GOOS, runtime.GOARCH)) + } + // 来自于 GoReleaser 的版本号 monitor.Version = version