Install "context" package in golang?

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

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

我遇到了类似的问题,以下是修复步骤:

  1. 下载最新版本 https://golang.org/doc/install?download=go1.9.2.linux-arm64.tar.gz

  2. 将tar文件解压到 /usr/local/ 目录下。

使用以下命令:
tar -xzvf go1.9.2.linux-arm64.tar.gz -C /usr/local

  1. 替换指向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:

  1. Download the latest version https://golang.org/doc/install?download=go1.9.2.linux-arm64.tar.gz

  2. Extract the tar to /usr/local/ .

Use Command ->
tar -xzvf go1.9.2.linux-arm64.tar.gz -C /usr/local

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

huangapple
  • 本文由 发表于 2017年3月15日 14:12:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/42802278.html
匿名

发表评论

匿名网友

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

确定