【发布时间】:2021-07-26 22:25:53
【问题描述】:
我已经安装了go1.16.3 darwin/amd64
去环境
GOPATH="/Users/hariwarshan/go"
GOROOT="/usr/local/go"
使用 vscode。 在 GOPATH/src/github.com/{username}/first
里面有 main.go 文件
package main
import (
"github.com/gorilla/mux"
)
func main() {
router := mux.NewRouter()
}
当我尝试导入多路复用器时,我只能看到以下问题
could not import github.com/gorilla/mux (cannot find package "github.com/gorilla/mux" in any of
/usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
/Users/hariwarshan/go/src/github.com/gorilla/mux (from $GOPATH))
我有两个问题。
- 我在 main.go 所在的目录 (GOPATH/src/github.com/{username}/first) 中给出了命令 go get github.com/gorilla/mux。对吗?
- 安装的文件在哪里。我可以看到一个名为 mux 的文件夹放置在 GOPATH/pkg/mod/github.com 中。如果它安装在那里,为什么问题指出它在里面 src/github.com em> 而不是 pkg/mod/github.com?
我什至尝试在 GOPATH/src/github.com/{username}/first 中提供 go mod init 和 go mod tidy没有任何工作。
请有人帮帮我。提前致谢
【问题讨论】:
-
如果你使用模块,你不需要在
GOPATH/src。查看入门教程并逐步了解它与您所做的可能有何不同。 -
2021 年你应该使用模块而不是
$GOPATH。请在下面查看我的回答,了解如何使用官方教程设置您的环境