代碼中的這一句使用prometheus2.28.0版本的代碼:
import "github.com/prometheus/prometheus/prompb"
我把require github.com/prometheus/prometheus v2.5.0+incompatible
修改為github.com/prometheus/prometheus v2.28.0
於是出現了下面的錯誤:
GOROOT=C:\Go #gosetup
GOPATH=C:\Users\ahfuzhang\go #gosetup
C:\Go\bin\go.exe list -modfile=D:/source/ahfuzhang/daily_coding/2021-08-13/remote_write_client/go.mod -m -json -mod=mod all #gosetup
go: errors parsing go.mod:
D:/source/ahfuzhang/daily_coding/2021-08-13/remote_write_client/go.mod:12: require github.com/prometheus/prometheus: version "v2.28.0" invalid: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2
到官網看,這個版本肯定是存在的!怎么樣才能引用最新的版本呢?
go.mod中使用commit id來代替:
打開:https://github.com/prometheus/prometheus/tags
選擇v2.28.0的commit id: ff58416
修改go.mod為 require github.com/prometheus/prometheus ff58416
編譯代碼后,自動修改為了require github.com/prometheus/prometheus v1.8.2-0.20210811141203-dcb07e8eac34
搞定