問題: 在作日誌收集系統時使用到etcd,其中server端在linux上,首先安裝第三方包(windows)(安裝過程可能會有問題,我遇到的是鏈接谷歌官網請求超時,若是已經出現下面的兩個文件夾而且文件夾中都有內容則能夠不理會錯誤):linux
go get -u -v github.com/coreos/etcd/clientv3
完成以後,在開發環境中會增長兩個文件夾:git
1. src\go.etcd.io 2. src\github.com\coreos
客戶端測試程序(go語言,命名爲main.go,注意etcd server端的ip地址換成你本身的):github
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 }
在該文件夾下執行,報錯以下:golang
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
這樣的錯誤緣由能夠參考:windows
https://blog.csdn.net/zhangyexinaisurui/article/details/87001028 ide
解決的辦法:測試
1. 在 import 的時候,不要引用 "github.com/coreos/etcd/clientv3",而是 "go.etcd.io/etcd/clientv3",緣由已在上面的連接有所說明:ui
//"github.com/coreos/etcd/clientv3" "go.etcd.io/etcd/clientv3"
而後使用上面的測試程序測試,若是還有問題,再使用下面的 2 方法試下。google
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")。spa
參考文獻: