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/clientv3
andgo.etcd.io/etcd/client/v3
are, somewhat confusingly, distinct packages that both use the package nameclientv3
.The
client/v3.Config
type has theUsername
field 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/clientv3
was an older name for the package from thegithub.com/coreos/etcd
repo 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.