Open kk-kwok opened 2 years ago
@kk-kwok @mvertes any workaround for this? facing the same problem
i have same problem
Same problem here
I am facing a similar problem with a library using net.Dialer.DialContext
when trying to import the HashiCorp Vault API.
To repro:
>yaegi -syscall -unsafe -unrestricted github.com/hashicorp/go-cleanhttp
run: /home/nf/go/src/github.com/traefik/plugindemo/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go:26:16: cannot use type func(*net.Dialer, context.Context, string, string) (net.Conn, error) as type func(context.Context, string, string) (net.Conn, error) in struct literal
I've also faced a similar issue when trying to develop traefik plugin (which uses yaegi as interpreter for code) and importing "cloud.google.com/go/pubsub". I've got the error:
error="github.com/Lasica/traefic-pubsub-forwarder: failed to import plugin code \"github.com/Lasica/traefic-pubsub-forwarder\": 1:21: import \"github.com/Lasica/traefic-pubsub-forwarder\" error: plugins-local/src/github.com/Lasica/traefic-pubsub-forwarder/pubsub_monitoring.go:8:2: import \"cloud.google.com/go/pubsub\" error: plugins-local/src/github.com/Lasica/traefic-pubsub-forwarder/vendor/cloud.google.com/go/pubsub/iterator.go:27:2: import \"cloud.google.com/go/pubsub/apiv1\" error: plugins-local/src/github.com/Lasica/traefic-pubsub-forwarder/vendor/cloud.google.com/go/pubsub/apiv1/doc.go:90:2: import \"google.golang.org/api/option\" error: plugins-local/src/github.com/Lasica/traefic-pubsub-forwarder/vendor/google.golang.org/api/option/option.go:13:2: import \"golang.org/x/oauth2/google\" error: plugins-local/src/github.com/Lasica/traefic-pubsub-forwarder/vendor/golang.org/x/oauth2/google/default.go:17:2: import \"cloud.google.com/go/compute/metadata\" error: plugins-local/src/github.com/Lasica/traefic-pubsub-forwarder/vendor/cloud.google.com/go/compute/metadata/metadata.go:69:10: cannot use type func(*net.Dialer, string, string) (net.Conn, error) as type func(string, string) (net.Conn, error) in struct literal"
will look at it.
I've noticed that while traefic and the library I was trying to import both use golang in version 1.19, the yaegi that traefik uses in version 0.15 uses golang in version 1.18. I've checked that the api in question (net.Dialer.Dial) was changed in 1.19. That's the likely casue of this problem:
https://github.com/traefik/traefik/blob/v2.9.8/go.mod https://github.com/googleapis/google-cloud-go/blob/b5b7cdec59df6a746ed7ffef0aad667ced8cbc87/go.mod https://github.com/traefik/yaegi/blob/v0.15.0/go.mod https://tip.golang.org/doc/go1.19
Any update on this?
Any update on this?
I'm still seeing this same issue with traefik 3.0.2 (which is on 1.22), which includes yaegi 0.16.1 (which is on 1.21).
When trying to load a plugin which imports the consulcatalog
provider (which I wish to extend with a feature), treafik fails to load the plugin:
..../vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go:26:16: cannot use type func(*net.Dialer, context.Context, string, string) (net.Conn, error) as type func(context.Context, string, string) (net.Conn, error) in struct literal"
Which comes from the following code:
func DefaultPooledTransport() *http.Transport {
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
While this API has changed way before Go version 1.21. DialContext
/does/ return context.Context, string, string
.
When debugging traefik, I do see that the interpreter context's GOROOT is ..../go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.3.darwin-amd64
Sadly, when I try to run yaegi on cli, and import my package, I get an even weirder error:
$ GOPATH=plugins-local/ yaegi
> import "github.com/hsmade/traefik-consul-az-provider"
1:21: import "github.com/hsmade/traefik-consul-az-provider" error: plugins-local/src/github.com/hsmade/traefik-consul-az-provider/plugin.go:9:2: import "github.com/traefik/genconf/dynamic" error: plugins-local/src/github.com/hsmade/traefik-consul-az-provider/vendor/github.com/traefik/genconf/dynamic/marshaler.go:9:1: cannot define new methods on non-local type struct {}
The 'type struct' it refers to isn't a struct, but a custom type.
Met similar issue in Traefik 3.0.4 while using DialContext to set Transport, any update on this one?
I'm still seeing this same issue with traefik 3.0.2 (which is on 1.22), which includes yaegi 0.16.1 (which is on 1.21). When trying to load a plugin which imports the
consulcatalog
provider (which I wish to extend with a feature), treafik fails to load the plugin:..../vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go:26:16: cannot use type func(*net.Dialer, context.Context, string, string) (net.Conn, error) as type func(context.Context, string, string) (net.Conn, error) in struct literal"
Which comes from the following code:
func DefaultPooledTransport() *http.Transport { transport := &http.Transport{ Proxy: http.ProxyFromEnvironment, DialContext: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, DualStack: true, }).DialContext,
While this API has changed way before Go version 1.21.
DialContext
/does/ returncontext.Context, string, string
. When debugging traefik, I do see that the interpreter context's GOROOT is..../go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.3.darwin-amd64
Sadly, when I try to run yaegi on cli, and import my package, I get an even weirder error:
$ GOPATH=plugins-local/ yaegi > import "github.com/hsmade/traefik-consul-az-provider" 1:21: import "github.com/hsmade/traefik-consul-az-provider" error: plugins-local/src/github.com/hsmade/traefik-consul-az-provider/plugin.go:9:2: import "github.com/traefik/genconf/dynamic" error: plugins-local/src/github.com/hsmade/traefik-consul-az-provider/vendor/github.com/traefik/genconf/dynamic/marshaler.go:9:1: cannot define new methods on non-local type struct {}
The 'type struct' it refers to isn't a struct, but a custom type.
hello @hsmade , do you have any workaround on this issue? I am facing the same one for now, though the version is 3.0.4.
Sadly I don't. I never managed to get past this issue
From 2022 to the current time they haven't fixed such problems, amazing. How to use redis for more flexible plugins or similar things is not even close to clear, well unsafe
is bad, but it turns out that no version of redis libraries hardly work.
The following program
sample.go
triggers an unexpected resultExpected result
Got
Yaegi Version
github.com/traefik/yaegi v0.11.2
Additional Notes