golang
  • Introduction
  • 环境安装
    • vscode
    • liteide
  • 第一个Go程序
  • Go项目结构
  • Go语言命令
  • 变量
  • 数据类型
    • array
    • slice
    • map
    • struct
    • interface
    • string
    • channel
    • 类型转换
  • 循环语句
  • HTTP编程
  • init函数
Powered by GitBook
On this page
  • MacOS
  • Reference

Was this helpful?

  1. 环境安装

vscode

前提:已经安装好go,并设置好gopath

MacOS

1、下载vs code

https://code.visualstudio.com/download

2、解压

下载下来的是一个zip包,解压后里面是一个.app文件,把它移动到应用程序中,并加入到程序坞中

3、安装go语言支持

在 Visual Studio Code中,点击左边四个图标中最下方的那个(如果把鼠标放在那上面会提示是Extensions),然后输入Go,查找并选中Rich Go language support for Visual Studio Code(一般是第一个,Microsoft的)

4、安装插件

需要在命令行下依次安装以下插件,这些都是go语言编写的。

go get -u -v github.com/nsf/gocode 
go get -u -v github.com/rogpeppe/godef 
go get -u -v github.com/golang/lint/golint 
go get -u -v github.com/lukehoban/go-find-references 
go get -u -v github.com/lukehoban/go-outline 
go get -u -v sourcegraph.com/sqs/goreturns 
go get -u -v golang.org/x/tools/cmd/gorename

如果安装失败,可以先在命令行设置代理服务器:

export http_proxy=http://ip:port
export https_proxy=http://ip:port

5、配置

可以做一些个性化的配置,比如是否需要在保存的时候自动构建等。点击 “code” -》“preferences” -》“settings”,进入配置页面。

点击 "User.settings" -》`...` -》“settings.json”

左边是默认配置,右边则用以下的内容覆盖(注意go.gopath与go.goroot要换成实际的目录),解释一下以下的配置,go.buildOnSave表示在保存的时候是否自动构建

{
    "go.buildOnSave": "off",
    "go.lintOnSave": "off",
    "go.vetOnSave": "off",
    "go.buildFlags": [],
    "go.lintFlags": [],
    "go.vetFlags": [],
    "go.formatOnSave": true,
    "go.formatTool": "goreturns",
    "go.goroot": "/usr/local/go",
    "go.gopath": "/Users/peng/Desktop/e/gopath",
    "window.zoomLevel": 1
}

如果配置有错的话,会有相应的提示。当把鼠标放在这一行上,会自动显示该字段的取值类型以及字段可能的取值,如下

6、worksapce

vscode的项目都是以workspace来管理的。点击“文件” -> “Add folder to workspace”,把项目添加到workspace中,然后就可以编辑代码了。可以添加多个项目到workspace中

Reference

[1] https://my.oschina.net/iyf/blog/599112

Previous环境安装Nextliteide

Last updated 5 years ago

Was this helpful?