Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install "context" package in golang?

Tags:

go

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.

like image 316
Jarvis Avatar asked Mar 15 '17 06:03

Jarvis


2 Answers

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

like image 95
zzn Avatar answered Sep 27 '22 17:09

zzn


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

like image 35
infiniteLearner Avatar answered Sep 27 '22 18:09

infiniteLearner