英文:
imported but undefined? Go
问题
我想使用 "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
我看到了这个问题:https://stackoverflow.com/questions/15405973/strange-golang-package-import-issue
这是相同的问题吗?还是我使用了错误的 "import" 或 "http" 的方式?
英文:
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 : https://stackoverflow.com/questions/15405973/strange-golang-package-import-issue
Is this the same problem? or did I use 'import' or 'http' in wrong way?
答案1
得分: 16
你想要导入的包名叫做"net/http",而不是"http"。请尝试以下代码:
import (
"net/http"
)
英文:
The package you want to import is called "net/http"
, not "http"
. Try:
import (
"net/http"
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论