mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 03:06:41 +08:00
修改defer关闭文件代码片段中的错误 (#403)
This commit is contained in:
@@ -4,10 +4,10 @@
|
||||
|
||||
```go
|
||||
func data(name string) string {
|
||||
f := os.Open(name, os.O_RDONLY, 0)
|
||||
f, _ := os.OpenFile(name, os.O_RDONLY, 0)
|
||||
defer f.Close() // idiomatic Go code!
|
||||
contents := io.ReadAll(f)
|
||||
return contents
|
||||
contents, _ := ioutil.ReadAll(f)
|
||||
return string(contents)
|
||||
}
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user