Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot find package "github.com/gorilla/mux" in any of:

Tags:

go

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.

My Go environment is here :

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.

like image 315
Diana Avatar asked Jan 09 '17 01:01

Diana


2 Answers

Could you try this steps to debug it:

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

    go list ... | grep gorilla

  3. 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

Please run this: export PATH=$PATH:$GOPATH/bin

How about running go run main.go ? is that working, if yes you should be able to do go build from your project path.

like image 123
James Avatar answered Nov 03 '22 10:11

James


I wish this helpful. You may off the 'mod'.

$ export GO111MODULE=off
like image 6
August Gong Avatar answered Nov 03 '22 08:11

August Gong