我想使用“http”包,并尝试导入
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
}
}
并获得以下输出
% go run httpget.go
# command-line-arguments
./httpget.go:4: imported and not used: "http"
./httpget.go:8: undefined: http
我看到了这个问题:Strange golang package import issue
这是同样的问题吗?还是以错误的方式使用'import'或'http'?
答案 0 :(得分:14)
您要导入的包名为"net/http"
,而不是"http"
。尝试:
import (
"net/http"
)