我正在尝试构建一个Traefik插件,并在基于https://github.com/traefik/plugindemo#local-mode的本地模式下进行测试。
现在这个插件什么也不做,只返回"Hello“。
以下是我的文件结构:

在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-introspectiongo.mod
module github.com/Hongbo-Miao/traefik-plugin-disable-graphql-introspection
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"))
}在根文件夹中,我有
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-introspectiondynamic_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服务器在http://localhost:5000运行
我要它通过Taefik被http://localhost:9000曝光
但是,当我跑的时候
traefik --configfile=traefik.yaml在根文件夹中,我得到了错误
traefik.go:79:命令traefik错误:未能执行;1:28:未定义: traefik_plugin_disable_graphql_introspection 119
Traefik插件由嵌入式Go解释器叶芝实时执行。
这个错误似乎是由Yaegi造成的,但是,我不知道如何调试。
任何导游都将不胜感激!
发布于 2022-05-11 17:57:48
收到汤姆·穆拉德的答复,谢谢你!https://github.com/traefik/plugindemo/issues/15#issuecomment-1123741949
您的错误意味着Yaegi无法找到
New包的traefik_plugin_disable_graphql_introspection函数。因此,您可以看出,Yaegi找到了您的插件,加载了它,但是找不到包。要解决这个问题,您需要将插件代码中的行package main更改为package traefik_plugin_disable_graphql_introspection。
在将package main更改为main.go文件中的package traefik_plugin_disable_graphql_introspection之后,它现在开始工作了!
https://stackoverflow.com/questions/72178972
复制相似问题