Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clientv3/namespace: cannot compile if a project vendors clientv3 and 'x/net/context' #7790

Closed
gyuho opened this issue Apr 21, 2017 · 3 comments
Milestone

Comments

@gyuho
Copy link
Contributor

gyuho commented Apr 21, 2017

Problem is clientv3.KV interface has golang.org/x/net/context type as first arguments to methods. If a project vendors github.com/coreos/clientv3 and its own golang.org/x/net/context, clientv3/namespace won't compile because of different import paths

e.g.

Copy this

package somepackage

import (
	"bytes"
	"context"
	"reflect"
	"testing"

	"github.com/coreos/etcd/clientv3"
	"github.com/coreos/etcd/clientv3/namespace"
	"github.com/coreos/etcd/embed"
	"github.com/coreos/etcd/etcdserver/api/v3client"
)

func someFunction() {
	cfg := embed.NewConfig()
	srv, _ := embed.StartEtcd(cfg)
	cli := v3client.New(srv.Server)
        // OR cli, _ := clientv3.New(clientv3.Config{Endpoints: []string{"localhost:2379"}})
	cli.KV = namespace.NewKV(cli.KV, "prefix")
}
./etcd_embedded_test.go:63: cannot use cli.KV (type "github.com/coreos/etcdlabs/vendor/github.com/coreos/etcd/clientv3".KV) as type "github.com/coreos/etcd/clientv3".KV in argument to namespace.NewKV:
	"github.com/coreos/etcdlabs/vendor/github.com/coreos/etcd/clientv3".KV does not implement "github.com/coreos/etcd/clientv3".KV (wrong type for Compact method)
		have Compact("github.com/coreos/etcdlabs/vendor/golang.org/x/net/context".Context, int64, ..."github.com/coreos/etcdlabs/vendor/github.com/coreos/etcd/clientv3".CompactOption) (*"github.com/coreos/etcdlabs/vendor/github.com/coreos/etcd/clientv3".CompactResponse, error)
		want Compact("golang.org/x/net/context".Context, int64, ..."github.com/coreos/etcd/clientv3".CompactOption) (*"github.com/coreos/etcd/clientv3".CompactResponse, error)
./etcd_embedded_test.go:63: cannot use namespace.NewKV(cli.KV, "prefix") (type "github.com/coreos/etcd/clientv3".KV) as type "github.com/coreos/etcdlabs/vendor/github.com/coreos/etcd/clientv3".KV in assignment:
	"github.com/coreos/etcd/clientv3".KV does not implement "github.com/coreos/etcdlabs/vendor/github.com/coreos/etcd/clientv3".KV (wrong type for Compact method)
		have Compact("golang.org/x/net/context".Context, int64, ..."github.com/coreos/etcd/clientv3".CompactOption) (*"github.com/coreos/etcd/clientv3".CompactResponse, error)
		want Compact("github.com/coreos/etcdlabs/vendor/golang.org/x/net/context".Context, int64, ..."github.com/coreos/etcdlabs/vendor/github.com/coreos/etcd/clientv3".CompactOption) (*"github.com/coreos/etcdlabs/vendor/github.com/coreos/etcd/clientv3".CompactResponse, error)
FAIL	github.com/coreos/etcdlabs/lru [build failed]

Without vendoring, same code runs fine.
Just open this for reference, if anyone faces the same issue.

@gyuho gyuho changed the title clientv3/namespace: cannot compile if the project vendors etcd/clientv3 clientv3/namespace: cannot compile if a project vendors clientv3 and 'x/net/context' Apr 21, 2017
@tfzxyinhao
Copy link

@gyuho
I have the same problem

@heyitsanthony heyitsanthony added this to the v3.3.0 milestone Apr 25, 2017
@heyitsanthony
Copy link
Contributor

This is blocked on grpc since it's still using /x/net/context. Supposedly go 1.9 will fix this with aliases?

@gyuho
Copy link
Contributor Author

gyuho commented Jul 28, 2017

@tfzxyinhao Do you have example snippet to reproduce? Turns out I did not vendor clientv3/namespace correctly. After vendoring it, the code compiles fine. Other context import issues should be resolved with Go 1.9 type alias (e.g. https://go-review.googlesource.com/c/35671/2/context/go19.go)

@gyuho gyuho closed this as completed Jul 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants