标签:return bin 设置 选项 lag com run flag 存在
sudo apt-get install golang
验证一下:
输入
$ go env
输出
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/sunchong/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/sunchong/go"
GORACE=""
GOROOT="/usr/lib/go-1.10"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.10/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
我这里选择了vs code
应用商店或者官网上安装好vscode
安装go 插件:搜索一下插件,安装量最高的那一个就是,Go for Visual Studio Code
当我们正想愉快的使用IDE进行开发go时,保存后会提示我们安装go相关的组件。。。
我们点击安装 Install All
有几个是可以安装成功的,有几个死活也装不上啊,开启FQ也不行。
Installing github.com/nsf/gocode SUCCEEDED
Installing github.com/uudashr/gopkgs/cmd/gopkgs SUCCEEDED
Installing github.com/ramya-rao-a/go-outline FAILED
Installing github.com/acroca/go-symbols FAILED
Installing golang.org/x/tools/cmd/guru FAILED
Installing golang.org/x/tools/cmd/gorename FAILED
Installing github.com/fatih/gomodifytags SUCCEEDED
Installing github.com/haya14busa/goplay/cmd/goplay SUCCEEDED
Installing github.com/josharian/impl FAILED
Installing github.com/rogpeppe/godef SUCCEEDED
Installing sourcegraph.com/sqs/goreturns FAILED
Installing github.com/golang/lint/golint FAILED
Installing github.com/cweill/gotests/... FAILED
Installing github.com/derekparker/delve/cmd/dlv SUCCEEDED
下面我们按照这个步骤再来一下
$GoPath/src/golang.org/x/tools
你的GoPath 目录下是否存在以上文件夹?没有新建
tools 目录下我们git一下
git clone https://github.com/golang/tools.git
tools 下会有一个tools文件夹
拷贝出来替换tools
执行命令
go install github.com/ramya-rao-a/go-outline
go install github.com/acroca/go-symbols
go install golang.org/x/tools/cmd/guru
go install golang.org/x/tools/cmd/gorename
go install github.com/josharian/impl
go install github.com/rogpeppe/godef
go install github.com/sqs/goreturns
go install github.com/golang/lint/golint
go install github.com/cweill/gotests/gotests
go install github.com/ramya-rao-a/go-outline
go install github.com/acroca/go-symbols
go install golang.org/x/tools/cmd/guru
go install golang.org/x/tools/cmd/gorename
go install github.com/josharian/impl
go install github.com/rogpeppe/godef
go install github.com/sqs/goreturns
go install github.com/golang/lint/golint
go install github.com/cweill/gotests/gotests
package main
import (
"fmt"
"os"
)
func main() {
if len(os.Args) > 1 {
fmt.Println("Hello World", os.Args[1]+os.Args[2])
}
if len(os.Args) > 2 {
fmt.Println("sunchong", os.Args[1]+os.Args[2])
}
}
切到这个文件目录下,执行一下:
go run hello_world.go 1 2
结果是
Hello World 12
sunchong 12
新建 Test.go 文件
package test
import "testing"
func TestSwitch(t *testing.T) {
i := 5
switch i {
case 1, 2, 3, 4, 5:
t.Log("yes")
case 6:
t.Log("yes2")
}
}
点击 run test | debug test
输出可爱的结果~~
有时 vscode 不能输出结果,那么需要进行一下配置:
文件 -- 首选项 -- 设置 -- 搜索 test
工作区设置 -- go test
这样设置:"go.testFlags": ["-v"]
这样我们可以高效地写我们的单元测试并能快速试错。
标签:return bin 设置 选项 lag com run flag 存在
原文地址:https://www.cnblogs.com/sunchong/p/11373017.html