如何在Windows系统编译Prometheus UI静态二进制文件?
编译Prometheus UI Windows二进制文件的依赖问题解决办法
问题背景
需要在Windows上编译Prometheus UI静态二进制文件,作为Grafana访问GCP托管Prometheus指标的认证代理。使用Go v1.19.3/v1.18.8运行go run main.go时出现依赖缺失提示,执行go get github.com/GoogleCloudPlatform/prometheus-engine/pkg/ui时返回错误:
go: github.com/GoogleCloudPlatform/prometheus-engine/pkg/ui: no matching versions for query "upgrade"
解决步骤
- 自动同步依赖:在项目源码目录执行
go mod tidy,该命令会自动识别源码中的import语句,拉取匹配的依赖版本,无需手动指定包路径。 - 配置Go代理:Windows环境下若无法拉取依赖,执行
go env -w GOPROXY=https://proxy.golang.org,direct开启官方代理,之后重新运行go mod tidy。 - 手动替换依赖:如果自动同步失败,先克隆仓库到本地GOPATH对应目录:
再在项目目录执行:git clone https://github.com/GoogleCloudPlatform/prometheus-engine.git %GOPATH%\src\github.com\GoogleCloudPlatform\prometheus-enginego mod edit -replace github.com/GoogleCloudPlatform/prometheus-engine/pkg/ui=%GOPATH%\src\github.com\GoogleCloudPlatform\prometheus-engine\pkg\ui go mod tidy - 拉取分支最新代码:若仓库无正式发布版本,直接指定master分支拉取:
go get github.com/GoogleCloudPlatform/prometheus-engine/pkg/ui@master
内容的提问来源于stack exchange,提问作者DevOpsNewbie
相关产品推荐
相关产品推荐

