go语言编译运行出错:imported and not used: "log"
来源:互联网 发布:黄鹤财富网络借贷 编辑:程序博客网 时间:2024/05/20 05:26
【问题】
使用代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package
main
import
(
"fmt"
"log"
"io/ioutil"
"net/http"
)
func main() {
fmt.Printf(
"this is EmulateLoginBaidu.go\n"
)
//var baiduMainUrl string
//baiduMainUrl = "http://www.baidu.com/";
//baiduMainUrl := "http://www.baidu.com/";
var baiduMainUrl string =
"http://www.baidu.com/"
;
fmt.Printf(
"baiduMainUrl=%s\n"
, baiduMainUrl)
//res, _, err := http.Get("http://bbs.golang-china.org/")
res, err := http.Get(
"http://bbs.golang-china.org/"
)
}
结果出错:
1
2
3
4
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"
即:
imported and not used: "xxx"【解决过程】
1.去试试,把对应模块注释掉:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package
main
import
(
"fmt"
//"log"
//"io/ioutil"
//"net/http"
)
func main() {
fmt.Printf(
"this is EmulateLoginBaidu.go\n"
)
//var baiduMainUrl string
//baiduMainUrl = "http://www.baidu.com/";
//baiduMainUrl := "http://www.baidu.com/";
var baiduMainUrl string =
"http://www.baidu.com/"
;
fmt.Printf(
"baiduMainUrl=%s\n"
, baiduMainUrl)
//res, _, err := http.Get("http://bbs.golang-china.org/")
//res, err := http.Get("http://bbs.golang-china.org/")
}
然后就可以了,就不会出错了。程序就可以继续编译和运行了:
1
2
3
D:\tmp\tmp_dev_root\go\src\github.com\user\EmulateLoginBaidu>go run EmulateLoginBaidu.go
this is EmulateLoginBaidu.go
baiduMainUrl=http://www.baidu.com/
如图:
【总结】
当go语言中,import了某个模块后,但是却没使用,就会导致:
imported and not used: "xxx"的错误,解决办法是:
注释(去掉)对应的模块,即可:
使得程序正常继续编译,正常运行。
阅读全文
0 0
- go语言编译运行出错:imported and not used: "log"
- Go 语言编译运行的小问题
- 命令行编译运行Go语言时参数代入的问题
- Go语言学习之log包(The way to go)
- go语言学习------Go 记录日志——log包
- go语言rune法substring出错问题
- go语言导入"C"出错问题
- linux下交叉编译放到arm板运行出错:-sh: ./no: not found
- go语言log包的学习(log,Logger)
- go 语言 command not found or ‘go’ is not recognized
- go语言编译环境搭建
- go语言编译环境安装
- the `gets' function is dangerous and should not be used.
- 编译出错和链接出错代替运行出错
- VS2008编译C语言出错
- centos7 go编译运行环境搭建
- Go工程目录介绍及go程序编译运行介绍
- Item29 Assume that move operations are not present,not cheap,and not used
- hibernate入门
- WEB前端之学会用PS很重要
- python3.5处理异常与python2的不同
- 解析json数据将数据填入表格对应的单元格
- 毕业一年之后
- go语言编译运行出错:imported and not used: "log"
- Linux 系统基础
- 这只是 arctic_coder的测试博客
- MySQL数据库配置菜单时没显示出来?
- QListWiget背景透明
- JSP中的九大内置对象和四大作用域
- SSM整合详解(个人理解)
- Hdu 2027 统计元音
- [python][pyqt4] 控件的使用