move defer after err check

This commit is contained in:
raziman 2020-09-25 17:14:07 +08:00
parent a6e0689cad
commit db80ab25c7

View File

@ -215,10 +215,10 @@ func contains(needle int, haystack []int) bool {
func appendFile(path string, content string) error {
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
defer f.Close()
if err != nil {
return tracerr.Wrap(err)
}
defer f.Close()
if _, err := f.WriteString(content); err != nil {
return tracerr.Wrap(err)
}