登录
首页 >  Golang >  Go问答

traefik.go:执行失败,无法解析新的命令:未找到:xxx

来源:stackoverflow

时间:2024-02-10 12:09:22 209浏览 收藏

积累知识,胜过积蓄金银!毕竟在Golang开发的过程中,会遇到各种各样的问题,往往都是一些细节知识点还没有掌握好而导致的,因此基础知识点的积累是很重要的。下面本文《traefik.go:执行失败,无法解析新的命令:未找到:xxx》,就带大家讲解一下知识点,若是你对本文感兴趣,或者是想搞懂其中某个知识点,就请你继续往下看吧~

问题内容

我正在尝试构建一个 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-introspection

go.mod

module github.com/hongbo-miao/traefik-plugin-disable-graphql-introspection

go 1.17

ma​​in.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 服务器运行在 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 即时执行。

该错误似乎是八重木引发的,但是,我不知道如何调试。

任何指南将不胜感激!


正确答案


得到了 Tom Moulard 的答复,谢谢! https://github.com/traefik/plugindemo/issues/15#issuecomment-1123741949

您的错误意味着Yaegi找不到traefik_plugin_disable_graphql_introspection包的New函数。因此,您可以看出 Yaegi 找到了您的插件并加载了它,但找不到该包。要解决此问题,您需要将插件代码中的 package main 行更改为 package traefik_plugin_disable_graphql_introspection

ma​​in.go 文件中将 package main 更改为 package traefik_plugin_disable_graphql_introspection 后,它现在可以工作了!

终于介绍完啦!小伙伴们,这篇关于《traefik.go:执行失败,无法解析新的命令:未找到:xxx》的介绍应该让你收获多多了吧!欢迎大家收藏或分享给更多需要学习的朋友吧~golang学习网公众号也会发布Golang相关知识,快来关注吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>