英文:
Install "context" package in golang?
问题
我正在尝试在golang中安装context
包,我是这样做的:
go get golang.org/x/net/context
但是当我执行import "context"
时,仍然出现以下错误:
cannot find package "context" in any of:
/usr/lib/go-1.6/src/context (from $GOROOT)
/home/saurabh/work/src/context (from $GOPATH)
有人可以建议如何安装这个包吗?我目前使用的是go1.6.2
版本。
英文:
I'm trying to install the context
package in golang, which I did like this :
go get golang.org/x/net/context
But when I do an import "context"
, I still get the following error :
cannot find package "context" in any of:
/usr/lib/go-1.6/src/context (from $GOROOT)
/home/saurabh/work/src/context (from $GOPATH)
Can anyone suggest how to install this package ? I'm currently using version go1.6.2
.
答案1
得分: 24
将import "context"
更改为import "golang.org/x/net/context"
。
但是在Go 1.7之后,你可以使用import "context"
,因为它已成为标准库。
Go 1.7将golang.org/x/net/context包移入标准库,命名为context。
请参阅1.7版本的发布说明:https://golang.org/doc/go1.7#context
英文:
change import "context"
to import "golang.org/x/net/context"
.
but after go 1.7 you can use import "context"
, as it had become a standard library.
> Go 1.7 moves the golang.org/x/net/context package into the standard library as context.
see 1.7 release notes: https://golang.org/doc/go1.7#context
答案2
得分: 1
我遇到了类似的问题,以下是修复步骤:
-
下载最新版本 https://golang.org/doc/install?download=go1.9.2.linux-arm64.tar.gz
-
将tar文件解压到 /usr/local/ 目录下。
使用以下命令:
tar -xzvf go1.9.2.linux-arm64.tar.gz -C /usr/local
- 替换指向go的符号链接:
sudo rm /usr/bin/go
sudo ln -s /usr/local/go/bin/go /usr/bin/go
参考链接:https://github.com/DieterReuter/arm64-docker-builder/issues/7
英文:
I faced similar issue , below are the steps to fix:
-
Download the latest version https://golang.org/doc/install?download=go1.9.2.linux-arm64.tar.gz
-
Extract the tar to /usr/local/ .
Use Command ->
tar -xzvf go1.9.2.linux-arm64.tar.gz -C /usr/local
- Replace the symlink pointing to go:
sudo rm /usr/bin/go
sudo ln -s /usr/local/go/bin/go /usr/bin/go
Reference: https://github.com/DieterReuter/arm64-docker-builder/issues/7
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论