Go 学习笔记
golang语言的特性
1.天然并发
- 从语言层面支持并发
- goroute, 轻量级线程,可以轻松创建成千上万个
- 基于CSP (Communicating Sequential Process) 模型实现
go fmt.Printf("hello, world")
3.channel
- 管道,类似unix/Linux 中的pipe
- 多个goroute之间通过channel通信
- 支持任何类型数据
func main() {
pipe := make(chan int,3)
pipe <- 1
pipe <- 2
}
交叉编译
# 1. Windows 平台编译 linux 和 Mac 的可执行文件
SET CGO_ENABLED=0 # 禁用CGO
SET GOOS=linux # 目标平台 linux or darwin
SET GOARCH=amd64 # 目标处理器架构64位 amd64
go build
# 1. MAC 平台编译 linux 和 windows 的可执行文件
CGO_ENABLED=0 # 禁用CGO
GOOS=linux # 目标平台 linux or windows
GOARCH=amd64 # 目标处理器架构64位 amd64