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:
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.17main.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: BarI have a GraphQL sever running at
I want it go through Taefik and expose by
However, when I run
traefik --configfile=traefik.yamlin 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
Newfunction of thetraefik_plugin_disable_graphql_introspectionpackage. 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 linepackage mainin your plugin's code, topackage traefik_plugin_disable_graphql_introspection.
After changing package main to package traefik_plugin_disable_graphql_introspection in the main.go file, it works now!