effective-go
https://golang.org/doc/effective_go
fmt
gofmt会自动格式化
type T struct {
name string // name of the object
value int // its value
}
comment
//和/* */两种,export的声明前应有comment
合并声明
var (
countLock sync.Mutex
inputCount uint32
outputCount uint32
errorCount uint32
)
命名
By convention, packages are given lower case, single-word names; there should be no need for underscores or mixedCaps
Another convention is that the package name is the base name of its source directory
it's neither idiomatic nor necessary to put Get into the getter's name. If you have a field called owner (lower case, unexported), the getter method should be called Owner (upper case, exported), not GetOwner
- package名字小写,单个字
- getter直接用变量名,不加Get
- interface名字在方法名后加-er
- 多个词的用首字母大写组合
分号
一般情况go会按照语法自动添加,只有for语句等需要主动添加