找不到软件包"github.com/gorilla/mux";在以下任何一项中: [英] cannot find package "github.com/gorilla/mux" in any of:
问题描述
我使用命令 go github.com/gorilla/mux
.我使用Golang制作了http服务器,并运行了该程序:
I use command go get github.com/gorilla/mux
. I made http server using Golang, and I run this program :
package main
import (
"fmt"
"html"
"log"
"net/http"
"github.com/gorilla/mux"
)
func main() {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/", Index)
log.Fatal(http.ListenAndServe(":8080", router))
}
func Index(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
但是我与这个错误冲突:
But I conflict this error :
/usr/local/go/bin/go build -i [/Users/imac/go/src]
http.go:9:5: cannot find package "github.com/gorilla/mux" in any of:
/usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
($GOPATH not set)
Error: process exited with code 1.
我的Go环境在这里:
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/imac/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/v9/fkc_t97s5v1g9sr938zzvxvh0000gn/T/go-build096571864=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
我为这个错误争取了一个星期,但我找不到解决方法.请帮助我.
I fight with this error for a week, But I can't find out solution. Please help me.
推荐答案
可以尝试以下步骤对其进行调试:
Could you try this steps to debug it:
-
ls -l/usr/local/go/src/github.com |grep大猩猩
-
cd $ GOPATH
转到列表... |grep大猩猩
如果在以上两个命令中没有看到大猩猩,则需要安装它: go get -v -u github.com/gorilla/mux
if you din't see gorilla in the above two command, then you need to install it:
go get -v -u github.com/gorilla/mux
请运行以下命令: export PATH = $ PATH:$ GOPATH/bin
运行 go run main.go
怎么样?是可行的,如果是的话,您应该可以从项目路径进行 go build
.
How about running go run main.go
? is that working, if yes you should be able to do go build
from your project path.
这篇关于找不到软件包"github.com/gorilla/mux";在以下任何一项中:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!