golang的内置类型
值类型:
- bool
- int(32 or 64), int8, int16, int32, int64
- uint(32 or 64), uint8(byte), uint16, uint32, uint64
- float32, float64
- string
- complex64, complex128
- array -- 固定长度的数组
引用类型:
- slice --切片
- map -- map集合
- chan -- 管道
常用内置函数
- append -- 追加元素到集合或切片里
- close -- 用来关闭连接或者管道
- delete -- 从map 中删除元素
- panic -- 停止常规的goroutine (panic和recover:用来做错误处理)
- recover -- 允许程序定义goroutine的panic动作
- real -- 返回complex的实部 (complex、real imag:用于创建和操作复数)
- imag -- 返回complex的虚部
- make -- 用来分配内存,返回Type本身(只能应用于slice, map, channel)
- new -- 用来分配内存,主要用来分配值类型,比如int、struct。返回指向Type的指针
- cap -- capacity是容量的意思,用于返回某个类型的最大容量(只能用于切片和 map)
- copy -- 用于复制和连接slice,返回复制的数目
- len -- 来求长度,比如string、array、slice、map、channel ,返回长度
- print、println -- 底层打印函数,在部署环境中建议使用 fmt 包
内置接口
type error interface { //只要实现了Error()函数,返回值为String的都实现了err接口
Error() String
}