1.命名规范

1.1.以字母或者下划线开头(不允许使用数字开头)

1.2.关键字不能当作变量名(25)个

break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var

1.3.此外,还有大约30多个预定义的名字,比如int和true等,主要对应内建的常量,类型和函数。

1.3.1内建常量:

true false iota nil

1.3.2内建类型:

int int8 int16 int32 int64
uint nint8 uint16 uint32 uint64 uintptr
float32 float64 complex128 complex64
bool byte rune string error

1.3.3内建函数:

make len cap new append copy close delete
complex real imag
panic recover

2.命名方法

2.1小驼峰命名法

变量第一个单词的首字母小写,后面的单词首字母大写
例如:userName

2.2大驼峰命名法

变量名字的首字母大写。
例如:UserName

2.3下划线命名法

使用下划线连接单词
例如:user_name