一尘不染

在以下任何位置都找不到软件包“ github.com/gorilla/mux”:

go

我使用命令go get github.com/gorilla/mux。我使用Golang制作了http服务器,并运行了以下程序:

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))

但我对此错误提出了抵触:

/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"

我为这个错误解决了一个星期,但是我找不到解决方法。请帮我。


阅读 726

收藏
2020-07-02

共1个答案

一尘不染

您可以尝试以下步骤对其进行调试:

  1. ls -l /usr/local/go/src/github.com | grep gorilla
  2. cd $GOPATH

go list ... | grep gorilla

  1. 如果在以上两个命令中没有看到大猩猩,则需要安装它: go get -v -u github.com/gorilla/mux

请运行以下命令: export PATH=$PATH:$GOPATH/bin

跑步go run main.go怎么样?是可行的,如果是的话,您应该能够go build从项目路径开始。

2020-07-02