最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】go语言运行出错:EmulateLoginBaidu.go:7:5: cannot find package "http" in any of

GO crifan 5828浏览 0评论

【问题】

折腾:

【已解决】go语言中的字符串

期间,用如下代码:

package main

import (
    "fmt"
    "log"
    "io/ioutil"
    "http"
)

func main() {
    fmt.Printf("this is EmulateLoginBaidu.go\n")
    baiduMainUrl = "http://www.baidu.com/";
    fmt.Printf(baiduMainUrl)
    res, _, err := http.Get("http://bbs.golang-china.org/")
}

去测试运行,结果出错:

D:\tmp\tmp_dev_root\go\src\github.com\user\EmulateLoginBaidu>go run EmulateLoginBaidu.go

EmulateLoginBaidu.go:7:5: cannot find package "http" in any of:

        D:\tmp\dev_install_root\Go\src\pkg\http (from $GOROOT)

        D:\tmp\tmp_dev_root\go\src\http (from $GOPATH)

如图:

cannot find package http in any of

即:

cannot find package "http" in any of

【解决过程】

1.很明显,是没找到http这个库。

2.参考之前的:

使用Go读取网页信息

貌似去需要去安装这个http包的:

http://golang.org/pkg/net/http/

3.接下来问题就是转化为:

【记录】go语言中安装http模块

4.解决了该问题后,接着就是已经解决了此问题了。

 

【总结】

摘录:

【记录】go语言中安装http模块

中的结论:

http是go语言的内置的库,所以无需安装,但是对应的引用方式是:

import "net/http"

而不是:

import "http"

此点需要注意。

转载请注明:在路上 » 【已解决】go语言运行出错:EmulateLoginBaidu.go:7:5: cannot find package "http" in any of

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.158 seconds, using 22.14MB memory