英文:
type clientv3.Config has no field or method Username
问题
代码如下所示:
import (
"context"
"crypto/tls"
"time"
"go.etcd.io/etcd/clientv3"
)
func main(){
...
config := clientv3.Config{}
config.Username = u.username
...
}
go.mod 文件如下所示:
module github.com/xxx
go 1.17
require (
github.com/coreos/etcd v2.3.8+incompatible // indirect
go.etcd.io/etcd v2.3.8+incompatible // indirect
)
出现以下错误信息:
config.Username undefined (type clientv3.Config has no field or method Username)
有没有办法解决这个问题?github.com/coreos/etcd/clientv3
和 go.etcd.io/etcd
有什么区别?
英文:
the code is:
import (
"context"
"crypto/tls"
"time"
"go.etcd.io/etcd/clientv3"
)
func main(){
...
config := clientv3.Config{}
config.Username = u.username
...
}
go.mod file
module github.com/xxx
go 1.17
require (
github.com/coreos/etcd v2.3.8+incompatible // indirect
go.etcd.io/etcd v2.3.8+incompatible // indirect
)
It fails with this message:
config.Username undefined (type clientv3.Config has no field or method Username)
Is there a way to resolve this problem?what's the difference between github.com/coreos/etcd/clientv3 and go.etcd.io/etcd?
答案1
得分: 1
go.etcd.io/etcd/clientv3
和go.etcd.io/etcd/client/v3
是两个有些混淆的不同包,它们都使用了包名clientv3
。
client/v3.Config
类型具有您期望的Username
字段,因此您可以更新您的代码以导入该包,而不是另一个包。
import (
…
"go.etcd.io/etcd/client/v3"
)
(https://play.golang.org/p/2SK2FUNxWs9)
github.com/coreos/etcd/clientv3
是github.com/coreos/etcd
存储库中的包在他们采用Go模块之前的旧名称。当他们转移到模块时,他们将规范的导入路径更改为go.etcd.io/etcd/client/v3
,但是(通过Go模块系统的一些怪癖)旧路径和新路径的混合仍然可以解析,使用旧路径的代码但从新的URL提供。您可能只想使用新的规范路径。
英文:
go.etcd.io/etcd/clientv3
and go.etcd.io/etcd/client/v3
are, somewhat confusingly, distinct packages that both use the package name clientv3
.
The client/v3.Config
type has the Username
field you expect, so perhaps you can update your code to import that package instead of the other one?
import (
…
"go.etcd.io/etcd/client/v3"
)
(https://play.golang.org/p/2SK2FUNxWs9)
github.com/coreos/etcd/clientv3
was an older name for the package from the github.com/coreos/etcd
repo before they adopted Go modules. When they moved to modules, they changed the canonical import path to go.etcd.io/etcd/client/v3
, but (through some quirks of the Go module system) a hybrid of the old and new paths can still be resolved, using the code from the old path but served from the new URL. You probably want to use only the new canonical path.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论