最后更新于10个月前
effective go 里面的例子:
for try := 0; try < 2; try++ { file, err = os.Create(filename) if err == nil { return } if e, ok := err.(*os.PathError); ok && e.Err == syscall.ENOSPC { deleteTempFiles() // Recover some space. continue } return }
if e, ok := err.(*os.PathError);
"type assertion" vs "errors.Is()"
e.Err == syscall.ENOSPC
e.Err实现了error接口,syscall.ENOSPC是一个常量,让一个error去比较一个常量,怎么会这样?
"errors.Is()" vs "=="(equality operator)