I'm getting a project started which uses etcd and the clientv3/concurrency package. The project uses go modules.
The README says to just run go get go.etcd.io/etcd/clientv3 but with go mod this is what it produces:
module etcd-buggy
go 1.14
require (
github.com/coreos/etcd v2.3.8+incompatible // indirect
go.etcd.io/etcd v2.3.8+incompatible
)
it defaults to an old version from 2017. A simple program like this compiles:
package main
import (
"log"
"go.etcd.io/etcd/clientv3"
)
func main() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{"localhost:12345"},
})
if err != nil {
log.Fatal(err)
}
_ = cli
}
but if I try to use the concurrency package it fails:
package main
import (
"log"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/clientv3/concurrency"
)
func main() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{"localhost:12345"},
})
if err != nil {
log.Fatal(err)
}
session, err := concurrency.NewSession(cli)
if err != nil {
log.Fatal(err)
}
_ = session
}
with this error:
# etcd-buggy
./main2.go:18:40: cannot use cli (type *"go.etcd.io/etcd/clientv3".Client) as type *"github.com/coreos/etcd/clientv3".Client in argument to concurrency.NewSession
at this point I tried to explicitily get the v3.4.7 tag but it fails:
go get go.etcd.io/etcd/[email protected]: go.etcd.io/[email protected]: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v3
I also tried to get the v3.3.20 tag but it fails too, first with this:
../../dev/go/pkg/mod/go.etcd.io/[email protected]+incompatible/clientv3/auth.go:22:2: module github.com/coreos/etcd@latest found (v2.3.8+incompatible), but does not contain package github.com/coreos/etcd/auth/authpb
../../dev/go/pkg/mod/go.etcd.io/[email protected]+incompatible/clientv3/client.go:28:2: module github.com/coreos/etcd@latest found (v2.3.8+incompatible), but does not contain package github.com/coreos/etcd/clientv3/balancer
../../dev/go/pkg/mod/go.etcd.io/[email protected]+incompatible/clientv3/client.go:29:2: module github.com/coreos/etcd@latest found (v2.3.8+incompatible), but does not contain package github.com/coreos/etcd/clientv3/balancer/picker
../../dev/go/pkg/mod/go.etcd.io/[email protected]+incompatible/clientv3/client.go:30:2: module github.com/coreos/etcd@latest found (v2.3.8+incompatible), but does not contain package github.com/coreos/etcd/clientv3/balancer/resolver/endpoint
../../dev/go/pkg/mod/go.etcd.io/[email protected]+incompatible/clientv3/client.go:31:2: module github.com/coreos/etcd@latest found (v2.3.8+incompatible), but does not contain package github.com/coreos/etcd/clientv3/credentials
../../dev/go/pkg/mod/go.etcd.io/[email protected]+incompatible/clientv3/watch.go:26:2: module github.com/coreos/etcd@latest found (v2.3.8+incompatible), but does not contain package github.com/coreos/etcd/mvcc/mvccpb
then if I try to update github.com/coreos/etcd/clientv3 to v3.3.20 I get this:
go: github.com/coreos/etcd imports
github.com/coreos/etcd/etcdmain imports
github.com/coreos/etcd/etcdserver imports
github.com/coreos/etcd/mvcc/backend imports
github.com/coreos/bbolt: github.com/coreos/[email protected]: parsing go.mod:
module declares its path as: go.etcd.io/bbolt
but was required as: github.com/coreos/bbolt
In the end the only thing that worked for me is to just go get go.etcd.io/etcd/clientv3@master, this is not a good solution however.
Is there something I'm missing to be able to use a tagged release of clientv3 with go modules ?
Same problem here with 3.3.20.
github.com/coreos/etcd/integration imports
github.com/coreos/etcd/etcdserver imports
github.com/coreos/etcd/mvcc/backend imports
github.com/coreos/bbolt: github.com/coreos/[email protected]: parsing go.mod:
module declares its path as: go.etcd.io/bbolt
but was required as: github.com/coreos/bbolt
go.mod file
module service-discovery
require (
github.com/coreos/etcd v3.3.20+incompatible
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/protobuf v1.3.5 // indirect
github.com/google/uuid v1.1.1 // indirect
go.uber.org/zap v1.14.1 // indirect
google.golang.org/genproto v0.0.0-20200408120641-fbb3ad325eb7 // indirect
google.golang.org/grpc v1.28.1 // indirect
)
go 1.14
Also results in this upon compilation
# github.com/coreos/etcd/clientv3/balancer/picker
../../go/pkg/mod/github.com/coreos/[email protected]+incompatible/clientv3/balancer/picker/err.go:37:44: undefined: balancer.PickOptions
../../go/pkg/mod/github.com/coreos/[email protected]+incompatible/clientv3/balancer/picker/roundrobin_balanced.go:55:54: undefined: balancer.PickOptions
# github.com/coreos/etcd/clientv3/balancer/resolver/endpoint
../../go/pkg/mod/github.com/coreos/[email protected]+incompatible/clientv3/balancer/resolver/endpoint/endpoint.go:114:78: undefined: resolver.BuildOption
../../go/pkg/mod/github.com/coreos/[email protected]+incompatible/clientv3/balancer/resolver/endpoint/endpoint.go:182:31: undefined: resolver.ResolveNowOption
Yeah got that one too, I think after adding replace github.com/coreos/bbolt => go.etcd.io/bbolt v3.3.20 the import error resolved and then I got this one.
The last bunch of errors happens because of #11721
i add replace github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.3 in go.mod, it resolved the error
Thank you liangjfblue both of my errors are now gone and my full go.mod file looks like this:
module service-discovery
replace github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.3
replace google.golang.org/grpc => google.golang.org/grpc v1.26.0 // indirect
require (
github.com/coreos/bbolt v0.0.0-00010101000000-000000000000 // indirect
github.com/coreos/etcd v3.3.20+incompatible
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.3.5 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/uuid v1.1.1 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.14.3 // indirect
github.com/jonboulle/clockwork v0.1.0 // indirect
github.com/prometheus/client_golang v1.5.1 // indirect
github.com/soheilhy/cmux v0.1.4 // indirect
github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
go.etcd.io/bbolt v1.3.4 // indirect
go.uber.org/zap v1.14.1 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
google.golang.org/genproto v0.0.0-20200408120641-fbb3ad325eb7 // indirect
google.golang.org/grpc v1.28.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)
go 1.14
I feel like we shouldn't have to resort to such hacks to just get a working client.
Having no experience with etcd, getting things working was extremely frustrating, almost to the point of completely dropping etcd from the project.
package main
import (
"context"
"go.etcd.io/etcd/clientv3"
"time"
)
func main() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{"192.168.20.204:2379", "192.168.20.205:2379", "192.168.20.206:2379"},
DialTimeout: 5 * time.Second,
})
if err != nil {
// handle error!
}
defer cli.Close()
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
_, err = cli.Put(ctx, "sample_key", "sample_value")
cancel()
if err != nil {
// handle error!
}
}
D:\Code\golang\gowork\测试\etcd>go version
go version go1.14 windows/amd64
D:\Code\golang\gowork\测试\etcd>go mod init test
go: creating new go.mod: module test
D:\Code\golang\gowork\测试\etcd>go mod tidy
......
go: found github.com/golang/groupcache/lru in github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e
go: test imports
go.etcd.io/etcd/clientv3 tested by
go.etcd.io/etcd/clientv3.test imports
github.com/coreos/etcd/auth imports
github.com/coreos/etcd/mvcc/backend imports
github.com/coreos/bbolt: github.com/coreos/[email protected]: parsing go.mod:
module declares its path as: go.etcd.io/bbolt
but was required as: github.com/coreos/bbolt
D:\Code\golang\gowork\测试\etcd>go mod edit -replace github.com/coreos/[email protected]=go.etcd.io/[email protected]
D:\Code\golang\gowork\测试\etcd>go mod tidy
......
go: finding module for package go.etcd.io/bbolt
go: finding module for package github.com/gorilla/websocket
go: found github.com/gorilla/websocket in github.com/gorilla/websocket v1.4.2
go: found go.etcd.io/bbolt in go.etcd.io/bbolt v1.3.4
go: go.etcd.io/[email protected] used for two different module paths (github.com/coreos/bbolt and go.etcd.io/bbolt)
D:\Code\golang\gowork\测试\etcd>go run main.go
......
go: found github.com/coreos/go-semver/semver in github.com/coreos/go-semver v0.3.0
# github.com/coreos/etcd/clientv3/balancer/resolver/endpoint
D:\GOPATH\pkg\mod\github.com\coreos\[email protected]+incompatible\clientv3\balancer\resolver\endpoint\endpoint.go:114:78: undefined: resolver.BuildOption
D:\GOPATH\pkg\mod\github.com\coreos\[email protected]+incompatible\clientv3\balancer\resolver\endpoint\endpoint.go:182:31: undefined: resolver.ResolveNowOption
# github.com/coreos/etcd/clientv3/balancer/picker
D:\GOPATH\pkg\mod\github.com\coreos\[email protected]+incompatible\clientv3\balancer\picker\err.go:37:44: undefined: balancer.PickOptions
D:\GOPATH\pkg\mod\github.com\coreos\[email protected]+incompatible\clientv3\balancer\picker\roundrobin_balanced.go:55:54: undefined: balancer.PickOptions
D:\Code\golang\gowork\测试\etcd>go mod edit -replace google.golang.org/[email protected]=google.golang.org/[email protected]
D:\Code\golang\gowork\测试\etcd>go run main.go
D:\Code\golang\gowork\测试\etcd>go build main.go
D:\Code\golang\gowork\测试\etcd>
go version 1.14
go mod init test
go mod edit -replace github.com/coreos/[email protected]=go.etcd.io/[email protected]
go mod edit -replace google.golang.org/[email protected]=google.golang.org/[email protected]
go mod tidy
go run main.go
import (
"github.com/coreos/etcd/clientv3"
)
i use github.com/coreos/etcd to replace go.etcd.io/etcd and it works
go mod init
go mod edit -replace github.com/coreos/[email protected]=go.etcd.io/bbolt@v1.3.4
go mod edit -replace google.golang.org/[email protected]=google.golang.org/grpc@v1.26.0
go mod tidy
Thank you liangjfblue both of my errors are now gone and my full go.mod file looks like this:
感谢 liangjfblue 我的两个错误现在都消失了,我的完整 go.mod 文件看起来像这样:
module service-discovery replace github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.3 replace google.golang.org/grpc => google.golang.org/grpc v1.26.0 // indirect require ( github.com/coreos/bbolt v0.0.0-00010101000000-000000000000 // indirect github.com/coreos/etcd v3.3.20+incompatible github.com/coreos/go-semver v0.3.0 // indirect github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect github.com/gogo/protobuf v1.3.1 // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.3.5 // indirect github.com/google/btree v1.0.0 // indirect github.com/google/uuid v1.1.1 // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 // indirect github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/grpc-ecosystem/grpc-gateway v1.14.3 // indirect github.com/jonboulle/clockwork v0.1.0 // indirect github.com/prometheus/client_golang v1.5.1 // indirect github.com/soheilhy/cmux v0.1.4 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect go.etcd.io/bbolt v1.3.4 // indirect go.uber.org/zap v1.14.1 // indirect golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect google.golang.org/genproto v0.0.0-20200408120641-fbb3ad325eb7 // indirect google.golang.org/grpc v1.28.1 // indirect sigs.k8s.io/yaml v1.2.0 // indirect ) go 1.14
老铁牛逼!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.
Most helpful comment
I feel like we shouldn't have to resort to such hacks to just get a working client.
Having no experience with etcd, getting things working was extremely frustrating, almost to the point of completely dropping etcd from the project.