英文:
mux.go:12: can't find import: "github.com/gorilla/context"`
问题
我正在尝试安装我的Go测试包,但是我一直收到以下错误信息:
D:\Developpement\golang\src\github.com\gorilla\mux\mux.go:12: 找不到导入: "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))
}
我的GOROOT
指向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
请注意,我已经将您的代码翻译为中文,但是由于代码中包含特殊字符,可能会导致格式混乱。
英文:
I'm trying to install my Go test package, but I keep getting this error:
D:\Developpement\golang\src\github.com\gorilla\mux\mux.go:12: can't find import: "github.com/gorilla/context"
Here's my code:
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))
}
My GOROOT
is pointing to Go's installation root, and GOPATH
to my workspace root.
EDIT
Here's the output of 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
答案1
得分: 1
我注意到你的目录名D:\Développement\golang\src\github.com\jpmonette\hello中有非ASCII字符。我不确定Go是否能正确处理这些字符。
Alex
英文:
I noticed your directory name D:\Développement\golang\src\github.com\jpmonette\hello has non ascii character. I am not sure if Go handles these properly.
Alex
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论