-
main 函数保存在名为 main 的包里. 如果 main 函数不在 main 包里, 构建工具就不会生成可执行的文件.
-
常量只能是 numeric 或者 string
There are boolean constants, rune constants, integer constants, floating-point constants, complex constants, and string constants. Rune, integer, floating-point, and complex constants are collectively called numeric constants.
:=
只能在函数/方法中使用
non-declaration statement outside of function body
-
[arrLength]int
初始化 array 的容量不能通过计算得出, 需要计算得出的话得用 make,left := make([]int, arrLength)
否则会报 non-constant array bound -
Go语言中的源代码定义为 UTF-8 文本, 不允许其他的表示. 在代码中写下字符
`⌘`
时, 用于创建程序的文本编辑器将符号 ⌘ 的 UTF-8 编码放入文本中. 当打印十六进制字节时, 我们只是将文件中的数据打印出来. -
runtime.GOMAXPROCS(1)
不代表就是单线程. 如果 Golang 运行时只分配一个逻辑处理器给调度器使用(runtime.GOMAXPROCS(1)
)来执行所有 goroutine. 即使只有这一个逻辑处理器也可以让多个 goroutine 并发运行.
基于调度器的内部算法, 一个正运行的goroutine在工作结束前, 可以被停止并重新调度. 调度器这样做的目的是防止某个goroutine长时间占用逻辑处理器. 当goroutine占用时间过长时, 调度器会停止当前正运行的goroutine, 并给其他可运行的goroutine运行的机会.
- Conversions
Conversions are expressions of the form T(x) where T is a type and x is an expression that can be converted to type T.
If the type starts with the operator * or <-, or if the type starts with the keyword func and has no result list, it must be parenthesized when necessary to avoid ambiguity:
|
|
Converting a constant yields a typed constant as result.
|
|
A non-constant value x can be converted to type T in any of these cases:
- x is assignable to T.
- ignoring struct tags (see below), x’s type and T have identical underlying types.
- ignoring struct tags (see below), x’s type and T are pointer types that are not defined types, and their pointer base types have identical underlying types.
- x’s type and T are both integer or floating point types.
- x’s type and T are both complex types.
- x is an integer or a slice of bytes or runes and T is a string type.
- x is a string and T is a slice of bytes or runes.