基础类型:
- Boolean types (
bool
) - Numeric types
- String types (
string
)
复合类型:
- Array types (
[len]Type
) - Slice types (
[]Type
) - Struct types (
struct
) - Map types (
map[KeyType]ValueType{}
)
特殊类型:
- Pointer types (
*Type
) 指针 - Function types (
func
) 函数 - Interface types (
interface
) 接口 - Channel types (
chan
) 通道
引用类型
基础类型 + Array + Struct 不是引用类型,其他几种(Slice + Map + Pointer + Function + Interface + Channel)都是引用类型,函数传参的时候需要记住这一点。
数值
uint8 the set of all unsigned 8-bit integers (0 to 255)
uint16 the set of all unsigned 16-bit integers (0 to 65535)
uint32 the set of all unsigned 32-bit integers (0 to 4294967295)
uint64 the set of all unsigned 64-bit integers (0 to 18446744073709551615)
int8 the set of all signed 8-bit integers (-128 to 127)
int16 the set of all signed 16-bit integers (-32768 to 32767)
int32 the set of all signed 32-bit integers (-2147483648 to 2147483647)
int64 the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)
float32 the set of all IEEE-754 32-bit floating-point numbers
float64 the set of all IEEE-754 64-bit floating-point numbers
complex64 the set of all complex numbers with float32 real and imaginary parts
complex128 the set of all complex numbers with float64 real and imaginary parts
byte alias for uint8
rune alias for int32
// 实现相关:
uint either 32 or 64 bits
int same size as uint
uintptr an unsigned integer large enough to store the uninterpreted bits of a pointer value
声明
var foo int
var foo int = 1
foo := 1
const foo = 1
const foo int = 1
注意:只有基础类型可以声明为常量。