配置Golang开发环境

设置环境变量

Linux/Unix

$ sudo vim /etc/envirnment # 在这个文件中加入以下变量
export $GOPATH = 你自己的路径
export $PATH = $PATH:$GOPATH/bin

Windows

  • GOPATH

GOPATH变量配置
GOPATH变量配置

  • PATH

PATH变量配置
PATH变量配置

项目克隆

$ cd $GOPATH/src
$ git clone your-project.git

代理设置

Go的包网址很多都在墙外,加个代理来获取吧。

Windows Shell

  • CMD
set http_proxy=http://localhost:8118
set https_proxy=http://localhost:8118
  • POWERSHELL
$env:http_proxy = $env:https_proxy = "http://127.0.0.1:8080"

Linux Shell

$ export http_proxy=http://localhost:8118
$ export https_proxy=http://localhost:8118

依赖管理 dep

$ go get -u -v github.com/golang/dep/cmd/dep

使用方法

恢复vendor目录

$ cd 'your dir.'
$ dep ensure -v
# 输出以下信息
(1/13) Wrote github.com/hu17889/go_spider@v1.0
(2/13) Wrote gopkg.in/yaml.v2@a5b47d31c556af34a302ce5d659e6fea44d90de0
(3/13) Wrote github.com/bitly/go-simplejson@v0.5.0
(4/13) Wrote github.com/mattn/go-isatty@57fdcb988a5c543893cc61bce354a6e24ab70022
(5/13) Wrote github.com/golang/protobuf@5a0f697c9ed9d68fef0116532c6e05cfeae00e55
(6/13) Wrote github.com/gin-gonic/gin@v1.2
(7/13) Wrote github.com/ugorji/go@c88ee250d0221a57af388746f5cf03768c21d6e2
(8/13) Wrote github.com/gin-contrib/sse@master
(9/13) Wrote github.com/andybalholm/cascadia@v1.0.0
(10/13) Wrote github.com/PuerkitoBio/goquery@v1.4.1
(11/13) Wrote gopkg.in/go-playground/validator.v8@v8.18.1
(12/13) Wrote golang.org/x/sys@master
(13/13) Wrote golang.org/x/net@master