使用工具: star 最多的 官方的 dep
翻墙问题:
- shadowsocks-qt5
sudo add-apt-repository ppa:hzwhuang/ss-qt5
sudo apt-get update
sudo apt-get install shadowsocks-qt5
- polipo
sudo apt-get install polipo
- sudo vim /etc/polipo/config
socksParentProxy = "localhost:1080"
socksProxyType = socks5
logLevel=4
- 重启polipo
sudo service polipo stop
sudo service polipo start
- 设置别名
alias hp="http_proxy=http://localhost:8123"
aliax hps="https_proxy=http://localhost:8123"
- 使用示例
hps go get -u -v github.com/labstack/echo/...
项目结构:
$GOPATH
- bin
dep gocode goimports golint go-outline gopkgs gorename impl godef goreturns godoc gurn等工具
- src
-
- my-github
myproject1
- vendor
项目依赖包
- main.go
- package1
自己写的包
- myproject2
Go vendor
要求 go 版本 大于 1.6
注意事项:
vendor 只能在 package 中存在,不能超越这个范围。也就意味着 vendor 不能是 $GOPATH/src 一级目录,否则报错。
vendor 可以嵌套使用,就是 vendor 里面可以还有 vendor
好处:
多项目管理,有自己的包依赖,工程隔离
可以平滑从非 vendor 项目转换为 vendor 项目
vendor 可以记录项目依赖包及其版本信息,任意升级换代,也任意维护
一个流程
cd /path/to/your/project
写好之后 dep init -v
运行:go run main.go
编译:go build -o www
常用命令:
dep init -v # 初始化项目依赖
dep ensure -v # 安装项目依赖
dep ensure -update # 更新依赖版本
vscode 库
hp go get -u -v github.com/bytbox/golint
hp go get -u -v github.com/golang/tools
hp go get -u -v github.com/lukehoban/go-outline
hp go get -u -v github.com/newhook/go-symbols
hp go get -u -v github.com/josharian/impl
hp go get -u -v github.com/sqs/goreturns
hp go get -u -v github.com/cweill/gotests
hp go get -u -v github.com/nsf/gocode
hp go get -u -v github.com/rogpeppe/godef
hp go get -u -v golang.org/x/tools/cmd/gorename
hp go get -u -v github.com/tpng/gopkgs
hp go get -u -v golang.org/x/tools/cmd/guru
注:
alias hp="http_proxy=http://localhost:8123" # 8123 会转到shadowsocks
常用库记录
Alternative JSON parser for Go that does not require schema (so far fastest)
a Go package to interact with arbitrary JSON
MongoDB driver for the Go language that implements a rich and well tested selection of features under a very simple API following standard Go idioms
Redigo is a Go client for the Redis database.
Package mysql provides a MySQL driver for Go’s database/sql package
High performance, minimalist Go web framework
Package zap provides fast, structured, leveled logging.
Package cron implements a cron spec parser and job runner
Package validator implements value validations for structs and individual fields based on tags.
provides cookie and filesystem sessions and infrastructure for custom session backends.
A golang http request library for humans