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

huangapple go评论73阅读模式
英文:

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"命令。

在命令行中,尝试以下步骤:

  1. cd [你的源代码目录]
  2. go mod init
  3. 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>

  1. cd [the dir of your source code]<br>
  2. go mod init<br>
  3. 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.

huangapple
  • 本文由 发表于 2021年8月27日 15:31:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/68949545.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定