使用工具: star 最多的 官方的 dep

翻墙问题:

  • shadowsocks-qt5
  1. sudo add-apt-repository ppa:hzwhuang/ss-qt5
  2. sudo apt-get update
  3. sudo apt-get install shadowsocks-qt5
  • polipo
  1. sudo apt-get install polipo
  • sudo vim /etc/polipo/config
  1. socksParentProxy = "localhost:1080"
  2. socksProxyType = socks5
  3. logLevel=4
  • 重启polipo
  1. sudo service polipo stop
  2. sudo service polipo start
  • 设置别名
  1. alias hp="http_proxy=http://localhost:8123"
  2. aliax hps="https_proxy=http://localhost:8123"
  • 使用示例
  1. 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
  1. - vendor

项目依赖包

  1. - main.go
  2. - 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

常用命令:

  1. dep init -v # 初始化项目依赖
  2. dep ensure -v # 安装项目依赖
  3. dep ensure -update # 更新依赖版本

vscode 库

  1. hp go get -u -v github.com/bytbox/golint
  2. hp go get -u -v github.com/golang/tools
  3. hp go get -u -v github.com/lukehoban/go-outline
  4. hp go get -u -v github.com/newhook/go-symbols
  5. hp go get -u -v github.com/josharian/impl
  6. hp go get -u -v github.com/sqs/goreturns
  7. hp go get -u -v github.com/cweill/gotests
  8. hp go get -u -v github.com/nsf/gocode
  9. hp go get -u -v github.com/rogpeppe/godef
  10. hp go get -u -v golang.org/x/tools/cmd/gorename
  11. hp go get -u -v github.com/tpng/gopkgs
  12. hp go get -u -v golang.org/x/tools/cmd/guru

注:

  1. alias hp="http_proxy=http://localhost:8123" # 8123 会转到shadowsocks

常用库记录

Go Popular Packages

awesome-go

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