traefik.go:命令 traefik 错误:无法评估新:未定义:xxx

我正在尝试构建一个 Traefik 插件并基于https://github.com/traefik/plugindemo#local-mode在本地模式下对其进行测试

现在这个插件什么都不做,只返回“Hello”。

这是我的文件结构:

http://img2.mukewang.com/6397e7310001b5cc06520348.jpg

在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

主程序


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


蝴蝶刀刀
浏览 142回答 1
1回答

繁星点点滴滴

得到了 Tom Moulard 的答复,谢谢!https://github.com/traefik/plugindemo/issues/15#issuecomment-1123741949你的错误是八重木找不到包New的功能traefik_plugin_disable_graphql_introspection。因此,您可以判断 Yaegi 找到了您的插件并加载了它,但找不到包。package main要解决此问题,您需要将插件代码中的行更改为package traefik_plugin_disable_graphql_introspection.在main.go文件中更改为后package main,它现在可以工作了!package traefik_plugin_disable_graphql_introspection
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go