收到以下错误

I am recieving an error while compilation.

Root cause is the file has import of context package, but however during compilation github.com/docker/docker/vendor/golang.org/x/net/context is getting referred a, any pointers on as how to make it to refer to context import instead of docker's vendor package

Summarizing the issue, import in the file is as follows

import "golang.org/x/net/context"

there is a method call which takes context object as an argument, however, there are two repositories which have context ,

  • golang.org/x/net/context
  • github.com/docker/docker/vendor/golang.org/x/net/context

During compilation based on length go is selecting the 2 repository. But method needs the 1st one golang.org/x/net/context. hence the type error in code snippet is recieved

    "-X main.version=dev-49-gc8cc01b -X main.commit=c8cc01b -X     main.branch=master" ./...
 github.com/influxdata/telegraf/plugins/inputs/docker
 plugins/inputs/docker/docker.go:103: cannot use c (type *client.Client) as     type DockerClient in assignment:
    *client.Client does not implement DockerClient (wrong type for  ContainerList method)
            have ContainerList("github.com/docker/docker/vendor/golang.org/x/net/context".Context, types.ContainerListOptions) ([]types.Container, error)
            want ContainerList("context".Context, types.ContainerListOptions) ([]types.Container, error) make: *** [build] Error 2  sh-4.2# vi plugins/inputs/docker/docker.go

Two options I can think of:

  1. Add an alias for the context import, e.g.

    goContext golang.org/x/net/context docContext github.com/docker/docker/vendor/golang.org/x/net/context

  2. Break the context dependencies into two files, or packages