Created
September 21, 2016 02:21
-
-
Save JeOam/1e338afed67c34dd60f8602a40ca866f to your computer and use it in GitHub Desktop.
Go 入门笔记
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Author
Author
有个被称作 Communicating Sequential Processes(顺序通信处理)(CSP, C. Hoare 发明的)还有一个叫做 message passing-model(消息传递)(已经运用在了其他语言中,比如 Erlang)。
Author
What does an underscore in front of an import statement mean in Golang?
import _ "net/http/pprof"This form of import makes clear that the package is being imported for its side effects, because there is no other possible use of the package: in this file, it doesn't have a name.
Author
代码格式化当前目录所有 go 文件:
go fmt ./...
Author
类型断言:
if v, ok := varI.(T); ok { // checked type assertion
Process(v)
return
}
// varI is not of type T如果转换合法,v 是 varI 转换到类型 T 的值,ok 会是 true;否则 v 是类型 T 的零值,ok 是 false,也没有运行时错误发生。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
new()和make()的区别:new(T)为每个新的类型T分配一片内存,初始化为 0 并且返回类型为*T的内存地址:这种方法 返回一个指向类型为 T,值为 0 的地址的指针,它适用于值类型如数组和结构体;它相当于&T{}。make(T) 返回一个类型为 T 的初始值,它只适用于3种内建的引用类型:切片、map 和 channel。换言之,new 函数分配内存,make 函数初始化;