Skip to content

Commit

Permalink
refactor(region): more idiomatic Go
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneM committed Sep 18, 2023
1 parent 9ddd329 commit 0b1dcd8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions config/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ func EnsureRegionsCache(ctx context.Context, c Config, opts GetRegionOpts) (Regi
debug.Println("[Regions] Ensure cache is filled")
var regionsCache RegionsCache
fd, err := os.Open(c.RegionsCachePath)
if err == nil {
if err != nil {
debug.Printf("[Regions] Fail to open the cache: %v\n", err)
} else {
json.NewDecoder(fd).Decode(&regionsCache)
fd.Close()
}
Expand Down Expand Up @@ -103,13 +105,13 @@ func EnsureRegionsCache(ctx context.Context, c Config, opts GetRegionOpts) (Regi

debug.Println("[Regions] Save the cache")
fd, err = os.OpenFile(c.RegionsCachePath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0750)
if err == nil {
json.NewEncoder(fd).Encode(regionsCache)
fd.Close()
} else {
if err != nil {
debug.Printf("[Regions] Failed to save the cache: %v\n", err)
return regionsCache, nil
}

json.NewEncoder(fd).Encode(regionsCache)
fd.Close()
return regionsCache, nil
}

Expand Down

0 comments on commit 0b1dcd8

Please sign in to comment.