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?
go.etcd.io/etcd/clientv3andgo.etcd.io/etcd/client/v3are, somewhat confusingly, distinct packages that both use the package nameclientv3.The
client/v3.Configtype has theUsernamefield you expect, so perhaps you can update your code to import that package instead of the other one?(https://play.golang.org/p/2SK2FUNxWs9)
github.com/coreos/etcd/clientv3was an older name for the package from thegithub.com/coreos/etcdrepo before they adopted Go modules. When they moved to modules, they changed the canonical import path togo.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.