golang 中 mutex 定义位于mutex.go,其定义如下:golang 的读写锁基于 mutex,其定义位于rwmutex.go, 其定义如下:RWMutex 基于 Mutex 实现,在加写锁上,RWMutex 性能略差于 Mutex。
新手很容易忘记手动关闭,或者写在了错误的位置:上边的代码能正确发起请求,但是一旦请求失败,变量 resp 值为 nil,造成 panic:panic: runtime error: invalid memory address or nil pointer dereference。