Skip to content

Commit 0b1dcd8

Browse files
committed
refactor(region): more idiomatic Go
1 parent 9ddd329 commit 0b1dcd8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

config/region.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ func EnsureRegionsCache(ctx context.Context, c Config, opts GetRegionOpts) (Regi
5252
debug.Println("[Regions] Ensure cache is filled")
5353
var regionsCache RegionsCache
5454
fd, err := os.Open(c.RegionsCachePath)
55-
if err == nil {
55+
if err != nil {
56+
debug.Printf("[Regions] Fail to open the cache: %v\n", err)
57+
} else {
5658
json.NewDecoder(fd).Decode(&regionsCache)
5759
fd.Close()
5860
}
@@ -103,13 +105,13 @@ func EnsureRegionsCache(ctx context.Context, c Config, opts GetRegionOpts) (Regi
103105

104106
debug.Println("[Regions] Save the cache")
105107
fd, err = os.OpenFile(c.RegionsCachePath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0750)
106-
if err == nil {
107-
json.NewEncoder(fd).Encode(regionsCache)
108-
fd.Close()
109-
} else {
108+
if err != nil {
110109
debug.Printf("[Regions] Failed to save the cache: %v\n", err)
110+
return regionsCache, nil
111111
}
112112

113+
json.NewEncoder(fd).Encode(regionsCache)
114+
fd.Close()
113115
return regionsCache, nil
114116
}
115117

0 commit comments

Comments
 (0)