英文:
How should I resolve this import problem with gorilla/mux?
问题
无法导入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
我已经使用命令"go get github.com/gorilla/mux"安装了gorilla mux,但是我得到了这个错误。点击这里查看图片描述
英文:
could not import github.com/gorilla/mux (cannot find package "github.com/gorilla/mux" in any of
C:\Program Files\Go\src\github.com\gorilla\mux (from $GOROOT)
C:\Users\lenovo\go\src\github.com\gorilla\mux (from $GOPATH))compilerBrokenImport
I have installed gorilla mux using the cmd "go get github.com/gorilla/mux" but I'm getting this error.enter image description here
答案1
得分: 2
看起来你在运行"go get"之前没有运行"go mod init"命令。
在命令行中,尝试以下步骤:
cd [你的源代码目录]
go mod init
go get github.com/gorilla/mux
如果需要更多信息,请运行:
go help mod
之后,你可能还需要重新启动VS Code。
英文:
Looks like you didn't run "go mod init" before the "go get".<br><br>
In cmd, try this:<br>
cd [the dir of your source code]
<br>go mod init
<br>go get github.com/gorilla/mux
<br>
For more information run:
go help mod
<br><br>
Afterwards, you might also need to restart VS Code.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论