Use deferred file close.

v0.11
Martin Dosch 4 weeks ago
parent 8f2bb80ebe
commit c4236dd164
No known key found for this signature in database
GPG Key ID: 52A57CFCE13D657D

@ -57,6 +57,7 @@ func readMessage(messageFilePath string) (string, error) {
if err != nil {
return output, fmt.Errorf("readMessage: %w", err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
@ -73,11 +74,6 @@ func readMessage(messageFilePath string) (string, error) {
}
}
err = file.Close()
if err != nil {
fmt.Println("error while closing file:", err)
}
return output, nil
}

@ -85,6 +85,7 @@ func parseConfig(configPath string) (configuration, error) {
if err != nil {
return output, fmt.Errorf("parseConfig: failed to open config file: %w", err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
@ -138,10 +139,6 @@ func parseConfig(configPath string) (configuration, error) {
}
}
}
err = file.Close()
if err != nil {
fmt.Println("error closing file:", err)
}
// Check if the username is a valid JID
output.username, err = MarshalJID(output.username)

Loading…
Cancel
Save