golang dev env

国内下载

wget -c https://mirrors.ustc.edu.cn/golang/go1.12.9.linux-amd64.tar.gz
wget -c https://dl.google.com/go/go1.12.9.linux-amd64.tar.gz
wget -c https://gomirrors.org/dl/go/go1.12.9.linux-amd64.tar.gz

goproxy

export GOPROXY=https://mirrors.aliyun.com/goproxy
export GOPROXY=https://goproxy.io
export GOPRIVATE=*.corp.example.com
GO111MODULE=on CGO_ENABLED=0 go build
GO111MODULE=on CGO_ENABLED=0 go mod vendor

离线编译

# 开发过程
go mod vendor
GO111MODULE=on CGO_ENABLED=0 go build -mod=vendor
git add go.mod go.sum vendor

# 编译
test -d  /usr/local/go/bin && export GOROOT=/usr/local/go && export PATH=$PATH:$GOROOT/bin
test -f go.mod  &&  GO111MODULE=on  go build -mod=vendor

golang 1.10 报错的解决办法:

go tool asm: exit status 2
flag provided but not defined: -V

runtime/internal/sys

flag provided but not defined: -std

解决: ubuntu 系统:
export GOROOT=/usr/lib/go

CentOS 系统:
export GOROOT=/usr/lib/golang

不同版本覆盖混用会导致如下报错:

解决办法:删除部署路径的golang,全新部署

# crypto/rc4
/usr/local/go/src/crypto/rc4/rc4_asm.go:15:18: (*Cipher).XORKeyStream redeclared in this block
previous declaration at /usr/local/go/src/crypto/rc4/rc4.go:61:6
# strings
/usr/local/go/src/strings/strings_decl.go:8:6: IndexByte redeclared in this block
previous declaration at /usr/local/go/src/strings/strings.go:150:34

# 或者如下报错:

+ go build -mod=vendor
cannot load crypto/x509/pkix: open /app/wwwroot/advertApi/vendor/crypto/x509/pkix: no such file or directory

snippet

  • int64 to String
import "strconv"
strconv.FormatInt(int64Value, 10)
  • string to int64
import "strconv"
int64Value, err := strconv.ParseInt(strValue, 10, 64)
    if err != nil {
        log.Fatal(err)
    }

依赖管理,推荐 govendor

go get github.com/kardianos/govendor
go get -u github.com/tools/godep
brew install glide or curl https://glide.sh/get | sh

vscode cmd tools

go get -v github.com/golang/lint/golint
go get -v github.com/tpng/gopkgs
go get -v github.com/lukehoban/go-outline
go get -v github.com/nsf/gocode
go get -v sourcegraph.com/sqs/goreturns
go get -v github.com/rogpeppe/godef

cmd tools

go get github.com/joho/godotenv/cmd/godotenv    dotenv

将静态文件打包到二进制中

go get -u -v github.com/jteeuwen/go-bindata/...
go get github.com/GeertJohan/go.rice/...

web

go get -u gopkg.in/gin-gonic/gin.v1
go get -u gopkg.in/macaron.v1
go get -u github.com/labstack/echo/...

lib

https://github.com/joho/godotenv

gprc

brew install protobuf protobuf-c
go get -u google.golang.org/grpc
go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger

json to struct

https://mholt.github.io/json-to-go/

优秀库

日志
https://github.com/golang/glog
https://github.com/sirupsen/logrus

错误处理 https://github.com/juju/errors

配置读取 https://github.com/spf13/viper

测试框架 https://onsi.github.io/ginkgo/
go get github.com/onsi/ginkgo/ginkgo go get github.com/onsi/gomega

高效json库 github.com/json-iterator/go

实用工具

依赖库改名 go get -u golang.org/x/tools/cmd/gomvpkg

client lib for DB/NOSQL/Kafka

github.com/jinzhu/gorm
github.com/go-xorm/xorm
github.com/go-sql-driver/mysql
github.com/garyburd/redigo/redis
gopkg.in/mgo.v2
gopkg.in/ldap.v2
github.com/go-xorm/xorm
github.com/bradfitz/gomemcache/memcache
go get gopkg.in/Shopify/sarama.v1 # kafka github.com/Shopify/sarama
github.com/smallnest/goreq # HTTP client lib

links

https://emacsist.github.io/2016/10/18/Go%E5%AD%A6%E4%B9%A0/
http://colobu.com/2015/09/07/gotchas-and-common-mistakes-in-go-golang/
http://colobu.com/2017/02/01/golang-summaries/
https://go-zh.org/doc/effective_go.html
//www.greatytc.com/p/f30da01eea97
https://medium.com/@_orcaman/most-imported-golang-packages-some-insights-fb12915a07

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,568评论 2 45
  • Astronomygonova - A wrapper for libnova -- Celestial Mech...
    JumboWu阅读 8,862评论 0 41
  • 海马爸爸家长能量场专业技能培训 微信群上的聊天记录如下 ————— 2017-05-29 ————— 高科橡塑一王...
    企鹅妈妈阅读 353评论 0 0
  • 1.有人说,一首老歌就像一位朋友,若干年后或者刹那之间,那些旋律会让你瞬间泪流满面。 2.既然已无路可退,那就只能...
    Ljx夹心阅读 368评论 0 0
  • 这几天在上海学习,因为是封闭式每天只有到凌晨才能爬楼梯听课 这两天的功课都没做,自己不能原谅自己啊 这两天零成交,...
    FAB何颖阅读 194评论 0 0