- Lets Go 笔者连载的 go 文字和视频教程
- A Tour of Go
- Go by Example
- Learn Go with Tests
- The-way-to-go
- golang-developer-roadmap
- How to Write Go Code
- Learning-golang
- Build Web Application With Golang
- Go 高级编程
- Go 101 包含了很多基础和高级主题
- Mastering Go
- Goland IDE
- Vscode/Sublime/Atom 等常用编辑器结合插件
- vim/Neovim + vim-go + coc.nvim
博客:
- https://octetz.com/docs/2019/2019-04-24-vim-as-a-go-ide/
- https://ictar.xyz/2019/05/14/an-overview-of-go-tooling/
- https://github.com/fedir/go-tooling-cheat-sheet/blob/master/go-tooling-cheat-sheet.pdf
- https://yourbasic.org/golang/
- https://golangbot.com/learn-golang-series/
- https://golangbot.com/learn-golang-series/
- https://github.com/pkg/errors 推荐使用
- https://github.com/juju/errors
- https://blog.golang.org/error-handling-and-go
- https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully
- https://zhuanlan.zhihu.com/p/82985617 Golang error 的突围
- https://imhanjm.com/2017/05/19/go%20logger%20日志实践/
如果有有一些库拉不下来又没有自己的代理,可以试试
export GOPROXY=https://goproxy.io
- gin
- grpc
个人推荐使用 gin,当然你可以参考一下 star 选择别的框架
- https://github.com/gin-gonic/contrib gin各种组件
- https://github.com/e421083458/gin_scaffold gin 脚手架
- https://github.com/mingrammer/go-web-framework-stars
- https://github.com/EDDYCJY/go-gin-example
- https://github.com/vsouza/go-gin-boilerplate
- https://github.com/gothinkster/golang-gin-realworld-example-app
gin 实战博客:
- https://segmentfault.com/a/1190000013808421 gin 连载博客
- https://www.cnblogs.com/xinliangcoder/p/11212573.html logrus日志
- https://marcoma.xyz/2019/03/17/gin-tutorial-7/
微服务框架:
- go kit: https://github.com/go-kit/kit
- kratos: https://github.com/bilibili/kratos B站go微服务框架
微服务代码示例:
- https://dzone.com/users/3214037/eriklupander.html 介绍 go 微服务的一系列博客
- https://github.com/callistaenterprise/goblog go 微服务代码示例和博客,介绍了微服务各种基础组件
- https://github.com/yun-mu/MicroServicePractice 微服务实践
- https://github.com/golang-standards/project-layout
- https://zhengyinyong.com/go-project-layout-design.html
GoMock框架使用指南 如何写出优雅的 golang 代码
静态语言编写单测相比动态语言要难一些,动态语言中比如 python 可以很容易用 mock.patch 来做属性/方法替换。 但是静态语言不行,一般难点在于如何去模拟外部依赖(比如数据库/rpc请求,redis 请求等):
- 接口(go 推荐面向接口编程,否则你很难使用 gomock 来编写单测)
- mysql: 如何 mock 数据库请求。使用 sqlmock,或者编写 dao 层 interface,然后 mock 这个dao层接口
- http: 使用 httpmock 来模拟请求返回值
- redis: 这里我试了下 miniredis 比较好用,基于 go 实现,无需真实的 redis server
也有一种方式在单测环境加入真实的db 和redis(比如 docker),然后单测读取测试环境的数据库来操作。 这样的好处是可以不使用各种 mock 库,直接操作真实的 mysql,测试代码写起来也更方便。
以下是一些单测相关的库:
- testing: 内置库
- github.com/stretchr/testify/assert: 用来做断言 assert 方便
- gomock(mockgen): 静态语言难以像动态语言直接属性替换,所以一般我们基于接口编写代码,然后可以生成接口 mock
- sqlmock: 如果依赖了数据库 mysql 等,可以使用 sqlmock 模拟数据库返回内容。(或者就在测试环境用真实的 mysql,测试完清理插入的测试数据)
- httpmock: 用来 mock 调 http 请求
- github.com/alicebob/miniredis 可以用来 mock redis,无需启动真实的 resdis server。试了下非常好用,也不用使用 mock 和真实的 redis 了。个人强烈推荐
- bouk/monkey: 通过替换函数指针的方式修改任意函数的实现,如果以上都无法满足需求,可以用这种比较 hack 的方式。可能需要禁止编译器内联优化 go test -gcflask=-l ./...
参考:
# 搜索函数,打断点,如果有同名函数的时候比较有用
funcs FuncName
# 打断点断点
b main.main
# go get -u github.com/derekparker/delve/cmd/dlv
dlv debug main.go
# 加上命令行参数
# https://github.com/go-delve/delve/issues/562
dlv debug ./cmd/unit-assignment-cli/main.go -- server- go-spew: 用来打印一些复杂结构方便调试 https://github.com/davecgh/go-spew
- dlv: 断点调试器
- https://draveness.me/golang-101 如何写出优雅的 golang 代码(好文推荐)
- https://github.com/golang/go/wiki/CodeReviewComments 作为 effective go 补充
- https://peter.bourgon.org/go-best-practices-2016/
- https://dave.cheney.net/practical-go/presentations/qcon-china.html
- https://golang.org/doc/effective_go.html
- https://talks.golang.org/2013/bestpractices.slide
- https://dave.cheney.net/practical-go
- https://github.com/codeship/go-best-practices
- https://github.com/uber-go/guide/blob/master/style.md uber 的 go 规范
- https://12factor.net/zh_cn/
- https://go-proverbs.github.io go谚语,类似 python 之禅
- https://the-zen-of-go.netlify.com/ zen of go
- https://bluxte.net/musings/2018/04/10/go-good-bad-ugly/
- https://developer.aliyun.com/article/739836 Go 开发关键技术指南
- https://developer.aliyun.com/article/740696 Go 面向失败编程
- https://yq.aliyun.com/articles/741747 带着服务器编程金刚经走进 2020 年
- https://developer.aliyun.com/article/742169 Go 开发关键技术指南 | 敢问路在何方?
# https://pmcgrath.net/how-to-get-golang-package-import-list
go list -f '{{range $imp := .Imports}}{{printf "%s\n" $imp}}{{end}}' | sort
go list -f '{{range $dep := .Deps}}{{printf "%s\n" $dep}}{{end}}' | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}'技术选型一般选择接口稳定,更新快,生态相对成熟,star 数量较高,用户广泛的库,坑少一点。 前后分离时代用 gin 之类的框架写app后台还是挺快的,但是感觉做并发不高的内部后台业务还是用脚本python/php之类的更快。 以下第三方库均可以通过 google + 关键词搜索到,同一行尽量按照流行程度从前往后列举,默认都是 github 上的包(只写了仓库后缀)。 也可以去 awesome-go 之类的去查找,然后根据 star 数目等作为参考选用。
- web/rpc框架: gin, grpc, beego
- 参数验证:go-playground/validator, bytedance/go-tagexpr
- json处理转换:go-simplejson/mapstructure
- 配置解析: viper(兼容很多格式)
- mysql orm: gorm, xorm, sqlx
- redis: go-redis, redigo
- Kafka: Shopify/sarama
- Elasticsearch: olivere/elastic, elastic/elasticsearch
- mongodb: mongodb/mongo-go-driver
- id生成器: rx/xid, satori/go.uuid, beinan/fastid, bwmarrin/snowflake
- cache(in memory): patrickmn/go-cache, golang/groupcache(分布式)
- 并发/协程池(star 数从低到高排序):
- 异步任务框架: machinery, gocelery
- 定时任务:robfig/cron, ouiqiang/gocron
- 熔断:hystrix-go, eapache/go-resiliency, cep21/circuit
- 限流: ulule/limiter, didip/tollbooth
- 日志: logrus, zap, mumberjack
- 调试:go-spew/dlv
- 图片处理:h2non/imaginary
- 网络库:fatih/pool; panjf2000/gnet
- 表格:go-echarts
- excel(XLSX): 360EntSecGroup-Skylar/excelize, tealeg/xlsx
- 转换工具:
- sql2go(sql -> go struct): http://stming.cn/tool/sql2go.html
- curl2go(curl -> go http code): https://mholt.github.io/curl-to-go/
- Json2go(json -> go struct): https://mholt.github.io/json-to-go/
- 热编译工具:gowatch
- 静态检查:golangci-lint
- 网络代理:goproxy
- 命令行: cobra
- 字符串处理工具:huandu/xstrings
- HTML 处理: PuerkitoBio/goquery
工具:
- https://github.com/smallnest/gen gorm struct 生成工具
- https://mholt.github.io/json-to-go/ json 转 go struct
- https://protogen.marcgravell.com/decode proto decode 工具
- https://gopherize.me/ 一个好玩的小工具,设计你喜欢的 gopher 形象
博客:
- https://zhuanlan.zhihu.com/p/22803609 redigo demo
- https://blog.biezhi.me/2018/10/load-config-with-viper.html viper 解析配置
- https://draveness.me/golang/concurrency/golang-context.html
- https://github.com/tiancaiamao/go-internals/tree/master/zh
- https://zhuanlan.zhihu.com/p/80853548 深度解密Go语言之 scheduler
- https://github.com/cch123/golang-notes
- https://draveness.me/golang/ Go 语言设计与实现
- pprof
- github.com/uber/go-troch: Flame graph profiler for Go programs,火焰图工具,配合压测看性能瓶颈
- https://cizixs.com/2017/09/11/profiling-golang-program/
- https://software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs
- https://github.com/dgryski/go-perfbook
- https://dave.cheney.net/high-performance-go-workshop/dotgo-paris.html
- https://stephen.sh/posts/quick-go-performance-improvements
- https://medium.com/@vigneshsk/how-to-write-high-performance-code-in-golang-using-go-routines-227edf979c3c
- https://udhos.github.io/golang-concurrency-tricks/
- https://go101.org/article/memory-leaking.html
- https://colobu.com/2019/08/28/go-memory-leak-i-dont-think-so/
- https://segmentfault.com/a/1190000016230264 Go Reflect 高级实践
- https://github.com/ksimka/go-is-not-good
- 50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs
- https://bluxte.net/musings/2018/04/10/go-good-bad-ugly/
https://github.com/austingebauer/go-leetcode
