在golang中如何测试地图或通道未初始化

var m map[int]int
var c chan int

How to test if m and c is uninitialized with make

You can compare the values with nil to see if they're initialized. For example:

var m map[int]int
var c chan int
fmt.Println("is m uninitialized:", m == nil) // true
fmt.Println("is c uninitialized:", c == nil) // true

m = make(map[int]int)
c = make(chan int)
fmt.Println("is m uninitialized:", m == nil) // false
fmt.Println("is c uninitialized:", c == nil) // false

playground example code - https://play.golang.org/p/FzhygumF4v

if m == nil || c == nil {
   wtf();
}