traefik.go: command traefik error: failed to eval New: undefined: xxx
traefik.go: command traefik error: failed to eval New: undefined: xxx
我正在尝试构建一个 Traefik 插件并基于 https://github.com/traefik/plugindemo#local-mode
在本地模式下对其进行测试
现在这个插件什么都不做,只是returns“你好”。
这是我的文件结构:
在 traefik/plugins-local/src/github.com/Hongbo-Miao/traefik-plugin-disable-graphql-introspection
文件夹中,我有:
.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: github.com/Hongbo-Miao/traefik-plugin-disable-graphql-introspection
go.mod
module github.com/Hongbo-Miao/traefik-plugin-disable-graphql-introspection
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"))
}
在根文件夹中,我有
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: github.com/Hongbo-Miao/traefik-plugin-disable-graphql-introspection
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: http://localhost:5000/
middlewares:
my-traefik-plugin-disable-graphql-introspection:
plugin:
traefik-plugin-disable-graphql-introspection:
headers:
Foo: Bar
我有一个 GraphQL 服务器 运行ing 在 http://localhost:5000
我希望它通过 Taefik 并通过 http://localhost:9000 公开
然而,当我运行
traefik --configfile=traefik.yaml
在根文件夹中,出现错误
traefik.go:79: command traefik error: failed to eval New: 1:28: undefined: traefik_plugin_disable_graphql_introspection 119
Traefik 插件由嵌入式 Go 解释器 Yaegi 即时执行。
这个错误似乎是八重木抛出的,但是我不知道如何调试。
任何指导将不胜感激!
从 Tom Moulard 那里得到了答复,谢谢! https://github.com/traefik/plugindemo/issues/15#issuecomment-1123741949
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
.
在 main.go 文件中将 package main
更改为 package traefik_plugin_disable_graphql_introspection
后,现在可以使用了!
我正在尝试构建一个 Traefik 插件并基于 https://github.com/traefik/plugindemo#local-mode
在本地模式下对其进行测试现在这个插件什么都不做,只是returns“你好”。
这是我的文件结构:
在 traefik/plugins-local/src/github.com/Hongbo-Miao/traefik-plugin-disable-graphql-introspection
文件夹中,我有:
.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: github.com/Hongbo-Miao/traefik-plugin-disable-graphql-introspection
go.mod
module github.com/Hongbo-Miao/traefik-plugin-disable-graphql-introspection
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"))
}
在根文件夹中,我有
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: github.com/Hongbo-Miao/traefik-plugin-disable-graphql-introspection
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: http://localhost:5000/
middlewares:
my-traefik-plugin-disable-graphql-introspection:
plugin:
traefik-plugin-disable-graphql-introspection:
headers:
Foo: Bar
我有一个 GraphQL 服务器 运行ing 在 http://localhost:5000
我希望它通过 Taefik 并通过 http://localhost:9000 公开
然而,当我运行
traefik --configfile=traefik.yaml
在根文件夹中,出现错误
traefik.go:79: command traefik error: failed to eval New: 1:28: undefined: traefik_plugin_disable_graphql_introspection 119
Traefik 插件由嵌入式 Go 解释器 Yaegi 即时执行。
这个错误似乎是八重木抛出的,但是我不知道如何调试。
任何指导将不胜感激!
从 Tom Moulard 那里得到了答复,谢谢! https://github.com/traefik/plugindemo/issues/15#issuecomment-1123741949
Your error means that Yaegi cannot find the
New
function of thetraefik_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 linepackage main
in your plugin's code, topackage traefik_plugin_disable_graphql_introspection
.
在 main.go 文件中将 package main
更改为 package traefik_plugin_disable_graphql_introspection
后,现在可以使用了!