我正在尝试安装我的 Go 测试包,但我不断收到此错误:
D:\Developpement\golang\src\github.com\gorilla\mux\mux.go:12: can't find import: "github.com/gorilla/context"
这是我的代码:
package main
import (
"github.com/gorilla/pat"
"net/http"
)
func main() {
mux := pat.New()
mux.Get("/user/:name/profile", http.HandlerFunc(profile))
http.Handle("/", mux)
log.Println("Listening...")
http.ListenAndServe(":3000", nil)
}
func profile(w http.ResponseWriter, r *http.Request) {
params := r.URL.Query()
name := params.Get(":name")
w.Write([]byte("Hello " + name))
}
MyGOROOT
指向 Go 的安装根目录和GOPATH
我的工作区根目录。
编辑
这是输出go env
:
D:\Développement\golang\src\github.com\jpmonette\hello>go env
set GOARCH=386
set GOBIN=
set GOCHAR=8
set GOEXE=.exe
set GOHOSTARCH=386
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\Développement\golang\
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_386
set CC=gcc
set GOGCCFLAGS=-g -O2 -m32 -mthreads
set CGO_ENABLED=1