Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imported but undefined? Go

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?

like image 909
otiai10 Avatar asked Aug 16 '13 04:08

otiai10


1 Answers

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

import (
    "net/http"
)
like image 152
rboyer Avatar answered Sep 28 '22 02:09

rboyer