Golang - 开发环境搭建
安装Golang
export goversion='1.19.5'
curl -O https://dl.google.com/go/go$goversion.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go$goversion.linux-amd64.tar.gz
mv /usr/local/go /usr/local/go$goversion
在~/.bashrc中设置环境变量
goversion='1.19.5'
export GOROOT=/usr/local/go$goversion
export GOPATH=$HOME/.go$goversion
export GOPROXY=https://goproxy.cn,direct
export GO111MODULE=on
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
安装dlv调试工具
github地址:https://github.com/go-delve/delve
go install github.com/go-delve/delve/cmd/dlv@latest
dlv工具使用
dlv debug
启动程序,执行的参数使用双横杠--追加即可
dlv debug cmd/main.go -- run -H 0.0.0.0
break (alias: p)
命令设置断点,后面指定包和函数,例如在main包的main函数处设置断点,即为:"break main.main"
b main.main
print (alias: p)
命令打印运行时的变量值
p currentPath
vscode常用golang包安装
go install -v github.com/uudashr/gopkgs/v2/cmd/gopkgs@v2.1.2
go install -v github.com/ramya-rao-a/go-outline@latest
go install -v github.com/cweill/gotests/gotests@latest
go install -v github.com/fatih/gomodifytags@latest
go install -v github.com/josharian/impl@latest
go install -v honnef.co/go/tools/cmd/staticcheck@latest
go install -v golang.org/x/tools/gopls@latest
go get -v github.com/stamblerre/gocode@latest
go install -v github.com/rogpeppe/godef@latest
go install -v github.com/go-delve/delve/cmd/dlv@latest
go install -v github.com/haya14busa/goplay/cmd/goplay@latest
本文来自博客园,作者:GreeneGe,转载请注明原文链接:https://www.cnblogs.com/greene/p/15811467.html