# Go
# Flag
- https://github.com/golang (opens new window)
- https://github.com/pkg (opens new window)
- https://go.dev (opens new window)
- https://github.com/golangclub/golangcn.org (opens new window)
- 缩短GO包导入URL https://github.com/niemeyer/gopkg (opens new window)
- https://github.com/studygolang (opens new window)
- 在JVM中运行 https://github.com/zxh0/jvm.go (opens new window)
- 监视和配置网络设备的工具 https://github.com/inexio/thola (opens new window)
- https://github.com/dominikh/go-tools (opens new window)
- json生成go数据结构 https://github.com/misakafs/json-to-go (opens new window)
- 【Golang】实现文件服务器断点续传 (opens new window)
- Go实现HTTP断点续传多线程下载 (opens new window)
- https://github.com/hwholiday/file_storage (opens new window)
- Golang信号处理和优雅退出守护进程 (opens new window)
Windows下可以安装MinGW-w64、MSYS2、Cygwin以调用GCC,Windows10下推荐使用WSL
插件化开发
# 学习
- go文档中文翻译 https://github.com/polaris1119/pkgdoc (opens new window)
- Go 语言文档中文翻译 (opens new window)
- Go 标准库中文文档 (opens new window)
- https://github.com/taigacute/GoDoc-CN (opens new window)
- https://github.com/golang-china/gopl-zh (opens new window)
- Go 语言中文开源图书、资料或文档 (opens new window)
- Go 开发者路线图 (opens new window)
- Go 学习之路 (opens new window)
- Go基本类型说明 (opens new window)
- Go语言小册 (opens new window)
- 模板语法指南 (opens new window)
- golang 学习笔记 (opens new window)
- https://doc.xuwenliang.com/docs/go (opens new window)
- Go 语言编程 (opens new window) - Golang电子书介绍如何使用Golang建立网络
- 《The Way to Go》中文译本,中文正式名《Go 入门指南 (opens new window)》
- 《Go 编程基础 (opens new window)》是一套针对Go语言的视频语音教程,主要面向新手级别的学习者。
- 第三方类库 (opens new window)
- Go 官方文档翻译 (opens new window)
- Go 指南 (opens new window)
- Go 简易教程 (opens new window)
- Go 语言实战笔记 (opens new window)
- Go 语言标准库 (opens new window)
- Go 语言高级编程(Advanced Go Programming) (opens new window)
- https://github.com/geektutu/high-performance-go (opens new window)
- Go命令教程 (opens new window)
- Go实战开发 (opens new window)
- Go语言博客实践 (opens new window)
- Java程序员的Golang入门指南 (opens new window)
- Network programming with Go 中文翻译版本 (opens new window)
- Revel 框架手册 (opens new window)
- 学习Go语言 (opens new window)
- https://github.com/miguelmota/ethereum-development-with-go-book (opens new window)
- 神奇的 Go 语言 (opens new window)
- https://github.com/TiantianUpup/go-study (opens new window)
- Go 语言 Web 应用开发系列教程 (opens new window)
- https://github.com/rubyhan1314/Golang-100-Days (opens new window)
- Go 编程实例 Go by Example (opens new window)
- https://github.com/lexkong/apiserver_demos (opens new window)
- https://github.com/jiujuan/go-collection (opens new window)
- https://github.com/hwholiday/learning_tools (opens new window)
- 中文学习资料 https://github.com/gwuhaolin/golang-book (opens new window)
- https://github.com/jincheng9/go-tutorial (opens new window)
- https://github.com/unknwon/go-study-index (opens new window)
- https://github.com/mao888/golang-guide (opens new window)
- 设计模式 https://github.com/tmrts/go-patterns (opens new window)
- https://github.com/0voice/Introduction-to-Golang (opens new window)
- https://github.com/golang-design (opens new window)
- https://github.com/cch123/golang-notes (opens new window)
- https://github.com/shgopher/GOFamily (opens new window)
- https://github.com/pibigstar/go-demo (opens new window)
- https://www.topgoer.com (opens new window)
- https://github.com/iswbm (opens new window)
- https://github.com/yangwenmai/learning-golang (opens new window)
- https://github.com/duanbiaowu/go-examples-for-beginners (opens new window)
- Go语法树入门 https://github.com/chai2010/go-ast-book (opens new window)
- https://github.com/halfrost/LeetCode-Go (opens new window)
- Go泛型入门 https://github.com/akutz/go-generics-the-hard-way (opens new window)
- Golang开发手记 https://github.com/kevinyan815/gocookbook (opens new window)
- 周刊 https://github.com/polaris1119/golangweekly (opens new window)
- https://gobyexample.com (opens new window)
- https://golang3.eddycjy.com (opens new window)
- https://draveness.me/golang (opens new window)
- https://talkgo.org (opens new window)
- https://github.com/golang101/golang101 (opens new window)
- https://github.com/yongxinz/gopher (opens new window)
- https://github.com/gocn (opens new window)
- https://github.com/astaxie/build-web-application-with-golang (opens new window)
- 日报 https://github.com/bigwhite/gopherdaily (opens new window)
- Go子语言 https://github.com/chai2010/ugo-compiler-book (opens new window)
- https://github.com/wa-lang/wa (opens new window)
- Go_想变厉害的大白菜的博客-CSDN博客 (opens new window)
- Go的隐秘世界:Goroutine调度机制概览 (opens new window)
- golang调度学习-调度流程 (opens new window)
- 系统调用,ptrace,go语言syscall (opens new window)
# 工具链
- 安装最新go https://github.com/golang/tools/tree/master/cmd/getgo (opens new window)
- go版本管理 https://github.com/stefanmaric/g (opens new window)
- https://github.com/voidint/g (opens new window)
- https://github.com/moovweb/gvm (opens new window)
- https://github.com/syndbg/goenv (opens new window)
- 调试器 https://github.com/go-delve/delve (opens new window)
- 实时重新加载 https://github.com/cosmtrek/air (opens new window)
- https://github.com/gravityblast/fresh (opens new window)
- https://github.com/beego/bee (opens new window)
- https://github.com/silenceper/gowatch (opens new window)
- https://github.com/codegangsta/gin (opens new window)
- https://github.com/oxequa/realize (opens new window)
- 深入理解Go之generate (opens new window)
- https://github.com/gohouse/converter (opens new window)
- https://github.com/Zhwt/yaml-to-go (opens new window)
- 正则在线测试 http://regoio.herokuapp.com (opens new window)
- 接口和结构体UML https://www.dumels.com (opens new window)
- 测试文件中单个函数
go test -v 文件名_test.go -test.run 函数名
# 直接指定函数不指定文件运行
go test -v -test.run 函数名
关键点 | 说明 |
---|---|
导入需要的包 | import testing (如果你是goland,那么可以忽略,因为ide就自动帮你加上) |
执行命令 | go test file_test.go |
测试文件命名 | 必须以_test.go结尾 |
功能测试的用力函数 | 必须以Test开头&&后头跟着的函数名不能以小写字母开头,比如:Testcbs 就是不行的,TestCbs就是ok的 |
功能测试参数 | testing.T |
压力测试用例函数 | 必须以Benchmark开头&&其后的函数名不能以小写字母开头(例子同上) |
压力测试参数 | testing.B |
测试信息 | .Log方法,默认情况下是不会显示的,只有在go test -v的时候显示 |
测试控制 | 通过Error/Errorf/FailNow/Fatal等来进行测试是否是失败,或者在失败的情况下的控制 |
压力测试命令 | go test -test.bench file_test.go |
压力测试的循环体 | 使用test.B.N |
关闭GC(垃圾回收器)
- 变量设置
go env -w GOGC=off
# Modules
命令 | 说明 |
---|---|
go mod init | initialize new module in current directory(在当前目录初始化mod) |
go mod download | download modules to local cache(下载依赖包) |
go mod edit | edit go.mod from tools or scripts(编辑go.mod |
go mod graph | print module requirement graph (打印模块依赖图) |
go mod tidy | add missing and remove unused modules(拉取缺少的模块,移除不用的模块) |
go mod vendor | make vendored copy of dependencies(将依赖复制到vendor下) |
go mod verify | verify dependencies have expected content (验证依赖是否正确) |
go mod why | explain why packages or modules are needed(解释为什么需要依赖) |
- 查看所有可升级依赖版本
go list -u -m all
添加依赖
- 添加依赖:
go get github.com/xxx/xxx
- 添加指定版本:
go get github.com/xxx/[email protected]
- 添加指定版本范围:
go get github.com/xxxx/xxx@'<v1.6.2'
- 添加指定
commit
的版本:go get github.com/xxxx/xxx@q2516faf3
升级依赖
- 升级
Major
:go get -u github.com/xxx/xxx
- 升级全部依赖的
Minor
或PATCH
版本:go get -u
- 升级全部依赖的
PATCH
版本:go get -u=patch
# Modules代理
查看Go的环境信息
go env
GOPROXY
GO 1.13
版本开始GOPROXY
支持多代理设置,通过,
隔开
- 通用
go env -w GOPROXY=https://goproxy.io,https://goproxy.cn,direct
- Linux
export GOPROXY=https://goproxy.io,https://goproxy.cn,direct
- Windows
setx /m GOPROXY "https://goproxy.io,https://goproxy.cn,direct"
当第一个
proxy
在处理ge get
所发出的HTTP
请求时,返回HTTP
状态码为404
或410
时,就会查找下一个proxy
GOPRIVATE
设置
GOPRIVATE
来跳过私有库,比如常用的Github
、Gitlab
、Gitee
,中间使用,
分隔
go env -w GOPRIVATE=*.github.com,*.gitlab.com,*.gitee.com
GOSUMDB
如果在运行
go mod vendor
时,提示Get https://sum.golang.org/lookup/xxxxxx: dial tcp 216.58.200.49:443: i/o timeout
, 则是因为Go 1.13
设置了默认的GOSUMDB=sum.golang.org
,这个网站是被墙了的,用于验证包的有效性,可以通过如下命令关闭
go env -w GOSUMDB=off
- https://mirrors.aliyun.com/goproxy (opens new window)
- https://mirrors.cloud.tencent.com/help/go.html (opens new window)
- https://github.com/goproxy (opens new window)
- https://github.com/goproxyio (opens new window)
- https://github.com/gomods/athens (opens new window)
- https://github.com/jfrog/gocenter (opens new window)
GoGUI →