GoLang调试工具Delve
1.先获取呗:
1
| go get -u github.com/derekparker/delve/cmd/dlv
|
2.编写测试代码呗:
1
2
3
4
5
6
| func main(){
http.HandleFunc("/test",func(writer http.ResponseWriter,req *http.Request){
//TODO
})
log.Fatal(http.ListenAndServe("127.0.0.1:8080",nil))
}
|
3.debug 启动:
4.打断点:
4.1):对方法打断点:
b main.函数名
4.2):运行到断点处:
c
4.3:对某一行打断点:
需要得到文件的位置再打断点:
b /Users/joker/go/src/…/test.go:14 对14行打断点
至于如何进行与ide上的操作一致的呢: 通过n,s
- n:相当于Java-Eclipse的F6
- s:相当于Java-Eclipse的F5
如何查看变量呢:p
p testName 则会输出testName的值
args:则会输出所有方法参数信息
locals:则会输出所有的本地变量
emmmmmmmm golang 的命令行编译感觉好不方便,还是想办法搞到ide上吧
用go玩Debug, Info, Error级别的log
直接上代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| package mylog
import (
"log"
"os"
)
var (
Debug *log.Logger
Info *log.Logger
Error *log.Logger
)
func init() {
log.Println("init ...")
Debug = log.New(os.Stdout, "[DEBUG] ", log.Ldate|log.Ltime|log.Lshortfile)
Info = log.New(os.Stdout, "[INFO] ", log.Ldate|log.Ltime|log.Lshortfile)
Error = log.New(os.Stderr, "[ERROR] ", log.Ldate|log.Ltime|log.Lshortfile)
}
package main
import "mylog"
func main(){
mylog.Debug.Println("good");
mylog.Info.Println("good");
mylog.Error.Println("good");
}
|
|