Skip to content

Commit 88aad5e

Browse files
dkorunicmjuraga
authored andcommitted
MINOR: go: Use errors.Is() and fs.ErrNotExist instead of os.IsNotExist()
1 parent bd8065e commit 88aad5e

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

configuration/configuration.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ package configuration
1717

1818
import (
1919
"encoding/json"
20+
"errors"
2021
"fmt"
22+
"io/fs"
2123
"math/rand"
2224
"os"
2325
"path/filepath"
@@ -223,7 +225,7 @@ func (c *Configuration) Load() error {
223225
c.storage = &StorageHCL{}
224226
}
225227
if err = c.storage.Load(c.HAProxy.DataplaneConfig); err != nil {
226-
if os.IsNotExist(err) {
228+
if errors.Is(err, fs.ErrNotExist) {
227229
log.Warningf("configuration file %s does not exists, creating one", c.HAProxy.DataplaneConfig)
228230
} else {
229231
return fmt.Errorf("configuration file %s not valid: %w", c.HAProxy.DataplaneConfig, err)

configuration/misc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"encoding/base64"
2020
"errors"
2121
"fmt"
22+
"io/fs"
2223
"os"
2324
"path"
2425
"strconv"
@@ -75,7 +76,7 @@ func processExists(pid int) bool {
7576

7677
func fileExists(filename string) bool {
7778
info, err := os.Stat(filename)
78-
if os.IsNotExist(err) {
79+
if errors.Is(err, fs.ErrNotExist) {
7980
return false
8081
}
8182
return !info.IsDir()

configuration/user.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
package configuration
1717

1818
import (
19+
"errors"
1920
"fmt"
21+
"io/fs"
2022
"os"
2123
"strings"
2224
"sync"
@@ -134,7 +136,7 @@ func (u *Users) RemoveUser(user types.User) error {
134136

135137
func (u *Users) getUsersFromUsersListSection(filename, userlistSection string) error {
136138
// if file doesn't exists
137-
if _, err := os.Stat(filename); os.IsNotExist(err) {
139+
if _, err := os.Stat(filename); errors.Is(err, fs.ErrNotExist) {
138140
return fmt.Errorf("cannot read %s, file does not exist", filename)
139141
}
140142
p, errP := parser.New(options.Path(filename))

0 commit comments

Comments
 (0)