gpt4 book ai didi

go - 不能使用 Context 作为类型 "handlerfunc"gin-gonic

转载 作者:IT王子 更新时间:2023-10-29 02:13:21 30 4
gpt4 key购买 nike

这个问题困扰我好久了。我正在使用 gin-gonic,每次我尝试使用 go run main.go 时,总是会出现此编译错误:

cannot use properties.Pong (type func(*"github.com/carlqt/geodude/vendor/github.com/gin-gonic/gin".Context)) as type "github.com/gin-gonic/gin".HandlerFunc in argument to router.RouterGroup.GET

但是当我使用 Visual Studio Code 终端并运行 go run 时,它会起作用。

这是 main.go 文件 https://gist.github.com/carlqt/c5f6b0d127c1ca124cf2fe8d620976a1

这是 property.go 文件:https://gist.github.com/carlqt/6edadf1dedc63b4b4e231891cae8e9a5

我的项目结构是这样的

enter image description here

编辑在 VS Code 和我的终端中为终端添加 go env。我会把它们放在屏幕截图上以避免人为错误

VS代码终端: enter image description here

iterm2 终端: enter image description here

注意如果我将 HandlerFunc 函数从属性文件夹放到 main.go 文件中,也可以避免这个问题。

最佳答案

好的,对所有这些困惑感到抱歉,但对我有用的是卸载 Go 并重新安装它。以前,Go 是使用 Homebrew 安装在我的机器上的。当我重新安装它时,我使用了谷歌的 mac 安装程序。现在一切都好了。

感谢您的帮助。

关于go - 不能使用 Context 作为类型 "handlerfunc"gin-gonic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39674575/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com