https://github.com/coreos/go-systemd
安装 etcd 的时候提示错误:
[root@JhouShuai etcdDemo]# go build main.go
go: finding github.com/coreos/go-systemd/journal latest
go: finding github.com/coreos/go-systemd latest
go: finding github.com/gogo/protobuf v1.2.1
build command-line-arguments: cannot load github.com/coreos/go-systemd/journal: no matching versions for query "latest"
cannot find module providing package github.com/coreos/go-systemd/journal
第一种方案:
go1.13错误。解决方式如下:
1.自己从github拉取go-systemd 并保存到 $GOPATH src 下
$ mkdir github.com
$ cd github.com
$ git clone https://github.com/coreos/go-systemd.git
$ cd go-systemd
$ pwd
/Users/zhoushuai/go/src/github.com/go-systemd
2.使用replace在go.mod中替换go-systemd
$ vim go.mod
replace github.com/coreos/go-systemd => /Users/zhoushuai/go/src/github.com/go-systemd
这里要注意的是:不要直接使用路径 github.com/coreos/go-systemd/journal,因为该路径下没有 go.mod 文件。需要之前上一层目录
第二种方案:
replace github.com/coreos/go-systemd => github.com/coreos/go-systemd/v22 v22.0.0
[root@JhouShuai www]# go mod tidy
go: downloading github.com/coreos/go-systemd/v22 v22.0.0
go: extracting github.com/coreos/go-systemd/v22 v22.0.0
[root@JhouShuai etcdDemo]# go build main.go
go: finding github.com/coreos/go-systemd/v22 v22.0.0
[root@JhouShuai etcdDemo]# ls
main main.go
[root@JhouShuai etcdDemo]# ./main
[key:"name1" create_revision:4 mod_revision:7 version:2 value:"lesroad" key:"name2" create_revision:5 mod_revision:8 version:2 value:"haha" ]