6

I want to use "http" package, and try to import

package main

import (
    "http"
)

func main() {
    resp, err := http.Get("https://api.github.com/repos/otiai10/myFirstGo")
    if err != nil {
        // do something
    }
    if resp != nil {
        // do something
    }
}

and got outputs below

% go run httpget.go
# command-line-arguments
./httpget.go:4: imported and not used: "http"
./httpget.go:8: undefined: http

I saw this question : Strange golang package import issue

Is this the same problem? or did I use 'import' or 'http' in wrong way?

Community
  • 1
  • 1
otiai10
  • 4,289
  • 5
  • 38
  • 50

1 Answers1

16

The package you want to import is called "net/http", not "http". Try:

import (
    "net/http"
)
rboyer
  • 356
  • 3
  • 6
  • (´-`).。oO( But, it seems strange that it says 'imported and not used: "http"'... "cannot import 'http'" is better, I think. Isn't it? – otiai10 Aug 16 '13 at 04:45
  • 3
    On go 1.1.2, running your example code yields a different (better) error: `httpget.go:4:2: cannot find package "http" in any of: /usr/local/go/src/pkg/http (from $GOROOT) /home/username/src/go/src/http (from $GOPATH)` – rboyer Aug 16 '13 at 04:55