interface类型转换
value interface{} |
defer
defer 语句会将函数推迟到外层函数返回之后执行。
推迟调用的函数其参数会立即求值,但直到外层函数返回前该函数都不会被调用。
数组类型 [n]T
表示拥有 n
个 T
类型的值的数组。
var a [10]int |
range
//当使用 `for` 循环遍历切片时,每次迭代都会返回两个值。第一个值为当前元素的下标,第二个值为该下标所对应元素的一份副本。 |
映射
make
函数会返回给定类型的映射,并将其初始化备用。
var m map[string]Vertex |
哈希表
Insert or update an element in map m
:
m[key] = elem |
Retrieve an element:
elem = m[key] |
Delete an element:
delete(m, key) |
Test that a key is present with a two-value assignment:
elem, ok = m[key] |
If key
is in m
, ok
is true
. If not, ok
is false
.
If key
is not in the map, then elem
is the zero value for the map’s element type.
Note: If elem
or ok
have not yet been declared you could use a short declaration form:
elem, ok := m[key] |
go panic: assignment to entry in nil map(没有初始化)
并发
var wg sync.WaitGroup |
var wg sync.WaitGroup |