准备
安装依赖管理
brew install dep
安装dep同时也会安装依赖Go
- 配置环境变量
vim ~/.zshrc
# Golang
export GOPATH=$HOME/Workspace/go
export GOBIN=/usr/local/go/bin
export PATH=$PATH:$GOBIN
. ~/.zshrc
- 更新阿里云源
go env -w GO111MODULE=on
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
示例
mkdir -p ~/Workspace/go/src/gin-basic && cd ~/Workspace/go/src/gin-basic
dep init
curl https://raw.githubusercontent.com/gin-gonic/gin/master/examples/basic/main.go > main.go
dep ensure -add -v github.com/gin-gonic/gin@v1.3
go run main.go
curl localhost:8080/ping
# pong
关于Gin更多介绍可以参考gin-gonic/gin