19

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

2 Answers 2

24

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
  • I did it, but it still doesn't work. I get an error in declaring an object like this : r.Context undefined (type *http.Request has no field or method Context), where r is a pointer to an object of type http.Request.
    – Jarvis
    Mar 15, 2017 at 10:59
  • 1
    @Jarvis I believe http.Request.Context is available only since 1.7. If you want to use r.Context you need to upgrade from 1.6.2 to 1.7+, then you'll also be able to use import "context". Here are the 1.7 net/http release notes.
    – mkopriva
    Mar 15, 2017 at 12:22
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.