問題: 在做日志收集系統時使用到etcd,其中server端在linux上,首先安裝第三方包(windows)(安裝過程可能會有問題,我遇到的是連接谷歌官網請求超時,如果已經出現下面的兩個文件夾並且文件夾中都有內容則可以不理會錯誤):
go get -u -v github.com/coreos/etcd/clientv3
完成之后,在開發環境中會增加兩個文件夾:
1. src\go.etcd.io 2. src\github.com\coreos
客戶端測試程序(go語言,命名為main.go,注意etcd server端的ip地址換成你自己的):

1 package main 2 3 import ( 4 "fmt" 5 etcd_client "github.com/coreos/etcd/clientv3" 6 //etcd_client "go.etcd.io/etcd/clientv3" 7 "time" 8 ) 9 10 func main() { 11 12 cli, err := etcd_client.New(etcd_client.Config{ 13 Endpoints: []string{"192.168.30.136:2379", "192.168.30.136:22379", "192.168.30.136:32379"}, 14 DialTimeout: 5 * time.Second, 15 }) 16 if err != nil { 17 fmt.Println("connect failed, err:", err) 18 return 19 } 20 21 fmt.Println("connect succ") 22 defer cli.Close() 23 }
在該文件夾下執行,報錯如下:
go run main.go
F:\Go\project\src\go_dev_yuanma\go_dev\day12\etcd_conn>go run main.go # github.com/coreos/etcd/clientv3 ..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:116:72: cannot use auth.call Opts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.AuthEnable ..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:121:74: cannot use auth.call Opts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.AuthDisable ..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:126:100: cannot use auth.cal lOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserAdd ..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:131:86: cannot use auth.call Opts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserDelete ..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:136:122: cannot use auth.cal lOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argumen t to auth.remote.UserChangePassword ..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:141:104: cannot use auth.cal lOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argumen t to auth.remote.UserGrantRole ..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:146:80: cannot use auth.call Opts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserGet ..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:151:72: cannot use auth.call Opts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserList ..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:156:106: cannot use auth.cal lOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argumen t to auth.remote.UserRevokeRole ..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:161:80: cannot use auth.call Opts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.RoleAdd ..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:161:80: too many errors
這樣的錯誤原因可以參考:
https://blog.csdn.net/zhangyexinaisurui/article/details/87001028
解決的辦法:
1. 在 import 的時候,不要引用 "github.com/coreos/etcd/clientv3",而是 "go.etcd.io/etcd/clientv3",原因已在上面的鏈接有所說明:
//"github.com/coreos/etcd/clientv3" "go.etcd.io/etcd/clientv3"
然后使用上面的測試程序測試,如果還有問題,再使用下面的 2 方法試下。
2. 可以到 github.com/coreos/etcd 地址下載所有的包,然后解壓縮到 src\github.com\coreos 路徑下,如果沒有該目錄則創建,並將解壓后的文件夾命名為 etcd(原來為etcd-master),再將前面改名后的 etcd文件夾拷貝到 src\go.etcd.io 目錄下,再使用測試程序測試下(測試前記着啟動etcd的server端,同時測試程序 import "go.etcd.io/etcd/clientv3")。
參考文獻:
- https://blog.csdn.net/zhangyexinaisurui/article/details/87001028