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

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

GO crifan 5145浏览 0评论

【背景】

折腾:

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

期间,需要搞清楚,如何在go语言中,安装http模块。

【折腾过程】

1.参考之前的:

【记录】学习如何写go语言代码

中的,好像是直接去go install就可以了?

2.但是看到:

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

中的写的是:

import "net/http"

而不是我此处的:

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

所以,猜测:

本身http就是go语言的内置的包,所以无需安装,但是需要改为:

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

然后试了试,结果是果然可以了:

D:\tmp\tmp_dev_root\go\src\github.com\user\EmulateLoginBaidu>go run EmulateLoginBaidu.go
# command-line-arguments
.\EmulateLoginBaidu.go:5: imported and not used: "log"
.\EmulateLoginBaidu.go:6: imported and not used: "io/ioutil"
.\EmulateLoginBaidu.go:12: undefined: baiduMainUrl
.\EmulateLoginBaidu.go:12: cannot assign to baiduMainUrl
.\EmulateLoginBaidu.go:13: undefined: baiduMainUrl
.\EmulateLoginBaidu.go:14: assignment count mismatch: 3 = 2

即,也还是有其他错误的,但是:

找到了此处的net/http的库,没有报错。

 

【总结】

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

import "net/http"

而不是:

import "http"

此点需要注意。

转载请注明:在路上 » 【记录】go语言中安装http模块

发表我的评论
取消评论

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.200 seconds, using 22.07MB memory