Reputation: 1
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?
Upvotes: 0
Views: 215
Reputation: 5197
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.
Upvotes: 1