traefik.go: command traefik error: failed to eval New: undefined: xxx

I am trying to build a Traefik plugin and test it in local mode based on

Right now this plugin does nothing and just returns "Hello".

Here is my file structure:

enter image description here

In the traefik/plugins-local/src/ folder, I have:

.traefik.yml

entryPoints: graphql-server-entrypoint: address: :9000
api: insecure: true dashboard: true
providers: file: filename: dynamic_conf.yaml
log: level: DEBUG
experimental: localPlugins: traefik-plugin-disable-graphql-introspection: modulename: 

go.mod

module
go 1.17

main.go

package main
import ( "context" "net/http"
)
type Config struct{}
func CreateConfig() *Config { return &Config{}
}
type DisableGraphQLIntrospection struct { next http.Handler name string
}
func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error) { return &DisableGraphQLIntrospection{ next: next, name: name, }, nil
}
func (a *DisableGraphQLIntrospection) ServeHTTP(rw http.ResponseWriter, req *http.Request) { rw.Write([]byte("hello"))
}

In the root folder, I have

traefik.yaml

entryPoints: graphql-server-entrypoint: address: :9000
api: insecure: true dashboard: true
providers: file: filename: dynamic_conf.yaml
log: level: DEBUG
experimental: localPlugins: traefik-plugin-disable-graphql-introspection: modulename: 

dynamic_conf.yaml

http: routers: graphql-server-entrypoint: service: graphql-server-service entrypoints: - graphql-server-entrypoint rule: Host(`localhost`) middlewares: - my-traefik-plugin-disable-graphql-introspection services: graphql-server-service: loadBalancer: servers: - url: middlewares: my-traefik-plugin-disable-graphql-introspection: plugin: traefik-plugin-disable-graphql-introspection: headers: Foo: Bar

I have a GraphQL sever running at

I want it go through Taefik and expose by

However, when I run

traefik --configfile=traefik.yaml

in the root folder, I got error

traefik.go:79: command traefik error: failed to eval New: 1:28: undefined: traefik_plugin_disable_graphql_introspection 119

Traefik plugins are executed on the fly by Yaegi, an embedded Go interpreter.

The error seems threw by Yaegi, however, I have no clue how to debug.

Any guide would be appreciate!

1 Answer

Got an answer from Tom Moulard and thanks!

Your error means that Yaegi cannot find the New function of the traefik_plugin_disable_graphql_introspection package. Therefore, you can tell that Yaegi found your plugin, loaded it, but could not find the package. To fix this, you need to change the line package main in your plugin's code, to package traefik_plugin_disable_graphql_introspection.

After changing package main to package traefik_plugin_disable_graphql_introspection in the main.go file, it works now!

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like