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