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:
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
Break the context dependencies into two files, or packages
Related
I'm trying to build a container with testcontainers and output the logs to stdout.
I have followed their documentation (https://golang.testcontainers.org/features/follow_logs/) but when writing the Accept function, I get an error:
func (g *TestLogConsumer) Accept(l Log) {
g.Msgs = append(g.Msgs, string(l.Content))
}
The problem is that I didn't import a certain package, so I can't use "Log".
I get the following error:
undeclared name: Log
The question is, which package should I import. How can I make vscode import these packages automatically for me ? I have installed the go extension, but it doesn't import anything automatically.
I need to use kmac Hashicorp's Vault implementation. However, when I run the code, the following simple import:
import (
"encoding/hex"
"fmt"
"github.com/hashicorp/vault/sdk/helper/kmac"
)
throws this error: no required module provides package github.com/hashicorp/vault/sdk/helper/kmac/kmac; to add it: go get github.com/hashicorp/vault/sdk/helper/kmac/kmac
If I run:
go get github.com/hashicorp/vault/sdk/helper/kmac/kmac
I get:
go get: module github.com/hashicorp/vault/sdk#upgrade found (v0.2.0), but does not contain package github.com/hashicorp/vault/sdk/helper/kmac/kmac
I also tested to download the latest version but I get the same error. Can I get help?
I'm trying to used github.com/spf13/viper which requires github.com/spf13/afero and that requires some of the 3rdparty/go/golang.org/x/text: packages. Till afero works, and when defining 3rdparty BUILD for text:* packages I get the following errors,
3rdparty/go/github.com/spf13/afero has remote dependencies which require local declaration:
--> golang.org/x/text/unicode/norm (expected go_remote_library declaration at 3rdparty/go/golang.org/x/text:unicode/norm)
--> golang.org/x/text/transform (expected go_remote_library declaration at 3rdparty/go/golang.org/x/text:transform)
I tried to define it like this in 3rdparty/go/golang.org/x/text/BUILD,
go_remote_library(
rev='342b2e1fbaa52c93f31447ad2c6abc048c63e475',
packages=[
'unicode/norm',
'transform',
]
)
And it still shows the same error. Plus now running buildgen.go fails with the following error,
Exception caught: (pants.build_graph.target.UnknownArgumentError) (backtrace omitted)
Exception message: Invalid target 3rdparty/go/golang.org/x/text:text: GoRemoteLibrary received unknown arguments:
packages = ['unicode/norm', 'transform']
Some more info,
- Pants version: 1.13.0
- pantsbuild.pants.contrib.go: 1.13.0
- Tried using 1.14.0 & 1.15.0 as well and got the same results
Simple example to recreate it,
package main
import (
"fmt"
"github.com/spf13/viper"
)
func main() {
viper.AutomaticEnv()
fmt.Printf("%s", viper.GetString("HOME"))
}
Also you can simply do pants resolve on the package to get the error,
pants resolve 3rdparty/go/github.com/spf13/viper
Thanks to the pants team, got the issue resolved.
buildgen.go does turn go_remote_library(pkg='foo') takes into go_remote_libraries targets.
We need to use go_remote_libraries (not go_remote_library) to specify multiple packages.
Using this works fine,
go_remote_libraries(
rev='342b2e1fbaa52c93f31447ad2c6abc048c63e475',
packages=[
'transform',
'unicode/norm',
]
)
I am trying to install ginkgo and gomega using the gopkg.
It is throwing the following error:
src/gopkg.in/onsi/ginkgo.v1/ginkgo_dsl.go:24:2: use of internal package not allowed
src/gopkg.in/onsi/ginkgo.v1/ginkgo_dsl.go:25:2: use of internal package not allowed
src/gopkg.in/onsi/ginkgo.v1/ginkgo_dsl.go:26:2: use of internal package not allowed
src/gopkg.in/onsi/ginkgo.v1/ginkgo_dsl.go:27:2: use of internal package not allowed
src/gopkg.in/onsi/ginkgo.v1/ginkgo_dsl.go:28:2: use of internal package not allowed
src/gopkg.in/onsi/ginkgo.v1/ginkgo_dsl.go:29:2: use of internal package not allowed
src/gopkg.in/onsi/gomega.v1/gomega_dsl.go:21:2: use of internal package not allowed
src/gopkg.in/onsi/gomega.v1/gomega_dsl.go:22:2: use of internal package not allowed
src/gopkg.in/onsi/gomega.v1/gomega_dsl.go:23:2: use of internal package not allowed
To my understanding, this is not a fatal error. I was able to download both ginkgo and gomega using gopkg even though I got the same warning messages. A brief look at the source code shows that gomega_dsl.go and ginkgo_dsl.go import code from an internal subdirectory. I do not see why that should be a problem, though. Getting the packages worked despite these warnings.
I'm running go-ethereum test codes for eth package.
When I run go test . under the eth directory, I get the following error :
eth/api.go:37:2: use of internal package not allowed
37th line of eth/api.go is as follows :
"github.com/ethereum/go-ethereum/internal/ethapi"
From what I understand, this import should not be calling the error, as this file is within go-ethereum project directory.
Running the same test command on others' machine does not produce this error, so I suspect that there is something wrong with my go settings.
What would be the problem? Appreciate your help