ThanLoo
7/8/2019 - 4:47 AM

go_config

下载 gotool 到相关目录

  $location = "$env:GOPATH\src\golang.org\x\tools\"
  if (!(Test-Path $location)) {
      mkdir $location
  }
  cd $location
  git clone https://github.com/golang/tools.git $location

Auto Install

$src = @(
    "github.com/mdempsky/gocode",
    "github.com/uudashr/gopkgs/cmd/gopkgs",
    "github.com/ramya-rao-a/go-outline",
    "github.com/acroca/go-symbols",
    "golang.org/x/tools/cmd/guru",
    "golang.org/x/tools/cmd/gorename",
    "github.com/cweill/gotests/...",
    "github.com/fatih/gomodifytags",
    "github.com/josharian/impl",
    "github.com/davidrjenni/reftools/cmd/fillstruct",
    "github.com/haya14busa/goplay/cmd/goplay",
    "github.com/godoctor/godoctor",
    "github.com/go-delve/delve/cmd/dlv",
    "github.com/stamblerre/gocode",
    "github.com/rogpeppe/godef",
    "github.com/sqs/goreturns",
    "golang.org/x/lint/golint",
    "github.com/zmb3/gogetdoc"
)
$path = if ($env:GOPATH.Contains(';')) {
    $env:GOPATH.Split(';')[0] #C:\Users\Administrator\go
}
else {
    $env:GOPATH
}
$success = @()
$fail = @()
foreach ($item in $src) {
    try {
        go get -v $item
        if ( !$LASTEXITCODE -eq 0 ) { 
            $fail += "$item failed 地址不存在或访问出错"
            continue
        }
        cd "$path\src\$item"
        go install
    }
    catch {
        $fail += "$item failed $_"
        continue
    }
    $success += "$item successed"
}

echo "Total: $($src.Length) Success: $($success.Length) Fail: $($fail.Length)"

foreach ($item in $fail) {
    echo $item
}
foreach ($item in $success) {
    echo $item
}

GoLint 安装

在{GOPATH}\src\golang.org\x下建立一个 golint的目录,在目录里面git bash,执行下面的命令

git clone https://github.com/golang/lint.git ./

在vscode的终端上 执行 如下命令安装:

go install golang.org\x\lint\golint

PS:VsCode Go:Install/Update 若失败则到相关目录下 go install

代理环境变量设置

[environment]::SetEnvironmentvariable("GO111MODULE","on","User")
[environment]::SetEnvironmentvariable("GOPROXY","https://goproxy.io","User")

VSCode 配置

  "go.buildOnSave": "workspace",
  "go.lintOnSave": "package",
  "go.vetOnSave": "package",
  "go.buildTags": "",
  "go.buildFlags": [],
  "go.lintFlags": [],
  "go.vetFlags": [],
  "go.coverOnSave": false,
  "go.useCodeSnippetsOnFunctionSuggest": false,
  "go.formatOnSave": true,
  "go.formatTool": "goreturns",
  "go.goroot": "C:\\Go",
  "go.gopath": "C:\\Users\\Administrator\\go",
  "go.gocodeAutoBuild": false,
  "go.autocompleteUnimportedPackages": true,
  "go.inferGopath": true,
  "go.docsTool": "gogetdoc"