GO环境搭建

环境搭建:https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/01.4.md


1、安装gosubmile

【gosublime自动安装失败,手动安装】

参考:https://note.youdao.com/ynoteshare1/index.html?id=2468dc1652bd08f6ab28ca81617ec1f6&type=note

 

点击菜单: Preferences --> Browse Packages

打开Packages directory

打开Bit Bash Here ,git clone gosublime 包

git clone [email protected]:DisposaBoy/GoSublime.git在 GoSublime\src 源代码目录中,新建 margo 子目录

 

将 GoSublime\src\margo.sh\extension-example 目录下的 extension-example.go 文件复制到

GoSublime\src\margo 目录 ,并改名 margo.go

重启 Sublime Text3 。

点击菜单项Preferences -> package settings -> GoSublime -> Settings - Uesrs,

配置GOPATH,GOROOT:

{

    "env": {

        "GOPATH": "F:/WORKSPACE/go-space", ##源码的*工作空间,注意必须放在src包下,否则运行错误

        "GOROOT": "e:/go"

    },

 

    "font_size": 14,

    "highlight_line": true,

    "highlight_modified_tabs": true,

    "ignored_packages":

    [

        "Vintage"

    ],

    "soda_classic_tabs": true,

    "soda_folder_icons": true,

    "tab_size": 4,

    "translate_tabs_to_spaces": true,

    "update_check": false,

    "word_wrap": true

}

 

快捷键

  • 在sublime打开控制台 Ctrl + B

  • 关闭sbulime中打开的控制台 Esc

  • 查看函数的声明 Ctrl + . + H

  • 查看函数源码 Ctrl + . + G

  • 调出GoSublime 支持的所有功能: cmd +.


2、安装SidebarEnhancements和Go Build

 


3、安装 gocode

go get -u github.com/nsf/gocode

gocode 将会安装在默认`$GOBIN`

另外建议安装gotests(生成测试代码):

先在sublime安装gotests插件,再运行:

go get -u -v github.com/cweill/gotests/...

 


4、安装Goimports:可以在开发过程时候自动引入包和删除没有使用的包

4.1 下载goimports

# 创建文件夹

mkdir $GOPATH/src/golang.org/x/

# 进入文件夹 cd $GOPATH/src/golang.org/x/

# 下载源码

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

# 安装

go install golang.org/x/tools/cmd/goimports

4.2 安装后打开 GoSublime 的配置文件,在配置文件中添加新的根配置项:

{

"fmt_cmd" :[ "goimports"]

}

 


5、新加一个Build System支持CTRL+B进行编译

GO环境搭建