VSCode搭建Golang开发环境

问题描述

JetBrains开发的IDE——GoLand收费




步骤

  1. 下载Golang
    VSCode搭建Golang开发环境_第1张图片

  2. 下载VSCode,Windows建议选择System Installer
    VSCode搭建Golang开发环境_第2张图片

  3. Extensions → 搜【Go】 → Install
    VSCode搭建Golang开发环境_第3张图片

  4. 测试代码

test.go

package main

import "fmt"

func main() {
	fmt.Println("Hello World!")
}

在TERMINAL处执行命令运行:go run test.go
VSCode搭建Golang开发环境_第4张图片

  1. 全部安装 Install All
    VSCode搭建Golang开发环境_第5张图片
    不出意外会装不上




安装Go插件

基本方法:缺啥装啥

如执行命令 go install github.com/haya14busa/goplay/cmd/goplay 报错

cannot find package "github.com/skratchdot/open-golang/open" in any of:
        c:\go\src\vendor\github.com\skratchdot\open-golang\open (vendor tree)
        c:\go\src\github.com\skratchdot\open-golang\open (from $GOROOT)
        C:\Users\Administrator\go\src\github.com\skratchdot\open-golang\open (from $GOPATH)

那么去github.com/skratchdot/open-golang下载,对应放在C:\Users\Administrator\go\src\github.com\skratchdot\open-golang\open

VSCode搭建Golang开发环境_第6张图片

PS:执行命令go install golang.org/x/lint/golint报错应该去github.com/golang/lint下载




go版本为1.14.4可以试试本人整理的插件包:

  1. 下载整理的插件包
  2. 解压到Go根目录
  3. 执行命令
go install github.com/mdempsky/gocode
go install github.com/uudashr/gopkgs/v2/cmd/gopkgs
go install github.com/ramya-rao-a/go-outline
go install github.com/acroca/go-symbols
go install github.com/cweill/gotests/...
go install github.com/fatih/gomodifytags
go install github.com/josharian/impl
go install github.com/davidrjenni/reftools/cmd/fillstruct
go install github.com/haya14busa/goplay/cmd/goplay
go install github.com/godoctor/godoctor
go install github.com/go-delve/delve/cmd/dlv
go install github.com/stamblerre/gocode
go install github.com/rogpeppe/godef
go install github.com/sqs/goreturns
go install golang.org/x/tools/cmd/guru
go install golang.org/x/tools/cmd/gorename
go install golang.org/x/lint/golint

本人在多台机子上测试通过

VSCode搭建Golang开发环境_第7张图片




重启VSCode,直接F5就能运行了
VSCode搭建Golang开发环境_第8张图片




配置Gopath(可选)

Settings → Extensions → Go → Gopath → Edit in settings.json → 添加 C:/Go
VSCode搭建Golang开发环境_第9张图片

{
    "go.gopath": "C:/Go"
}




参考文献

  1. 解决 VS Code 中 golang.org 被墙导致的 Go 插件安装失败问题

你可能感兴趣的:(Golang,golang)