我应该如何解决 gorilla/mux 的导入问题?

问题描述 投票:0回答:2

无法导入 github.com/gorilla/mux(在任何一个中都找不到包“github.com/gorilla/mux”) C:\Program Files\Go\src\github.com\gorilla\mux (来自 $GOROOT) C:\Users\lenovo\go\src\github.com\gorilla\mux (来自 $GOPATH))compilerBrokenImport

我已经使用 cmd“go get github.com/gorilla/mux”安装了 gorilla mux,但出现此错误。enter image description here

go gorilla
2个回答
2
投票

看起来您没有在“go get”之前运行“go mod init”。

在cmd中,试试这个:

  1. cd [the dir of your source code]

  2. go mod init

  3. go get github.com/gorilla/mux

欲了解更多信息,请运行:

go help mod


之后,您可能还需要重新启动 VS Code。


0
投票

我遇到了具有相同症状的问题: 如果您在 main.go 文件中只导入“gorilla/mux”而不是“github.com/gorilla/mux”,编译器将无法合并正确的包。

代替:

import (
    "gorilla/mux"
   // other imports omitted for brevity
)

尝试:

import (
    "github.com/gorilla/mux"
   // other imports omitted for brevity
)
© www.soinside.com 2019 - 2024. All rights reserved.