Re-use err variable, instead of creating new error vars

This commit is contained in:
Matt Baer 2022-12-26 13:17:56 -05:00
parent baaf0580f5
commit 7a84d27dca

18
app.go
View file

@ -513,9 +513,9 @@ requests. We recommend supplying a valid host name.`)
// old sockets will remain after server closes;
// we need to delete them in order to open new ones
removeSocketErr := os.Remove(bindAddress)
if removeSocketErr != nil && !os.IsNotExist(removeSocketErr) {
log.Error("%s already exists but could not be removed: %v", bindAddress, removeSocketErr)
err = os.Remove(bindAddress)
if err != nil && !os.IsNotExist(err) {
log.Error("%s already exists but could not be removed: %v", bindAddress, err)
os.Exit(1)
}
} else {
@ -526,16 +526,16 @@ requests. We recommend supplying a valid host name.`)
log.Info("Serving on %s://%s", protocol, bindAddress)
log.Info("---")
listener, listenErr := net.Listen(network, bindAddress)
if listenErr != nil {
log.Error("Could not bind to address: %v", listenErr)
listener, err := net.Listen(network, bindAddress)
if err != nil {
log.Error("Could not bind to address: %v", err)
os.Exit(1)
}
if network == "unix" {
chmodSocketErr := os.Chmod(bindAddress, 0o666)
if chmodSocketErr != nil {
log.Error("Could not update socket permissions: %v", chmodSocketErr)
err = os.Chmod(bindAddress, 0o666)
if err != nil {
log.Error("Could not update socket permissions: %v", err)
os.Exit(1)
}
}