mux.go:12: 找不到导入: “github.com/gorilla/context”

huangapple go评论88阅读模式
英文:

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

huangapple
  • 本文由 发表于 2013年11月14日 10:39:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/19968509.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定