Skip to content

Commit

Permalink
fix: use os.ReadFile to solve leaking files problem in loadLocales (#90)
Browse files Browse the repository at this point in the history
This change fixes the leaking files problem in loadLocales by
invoking os.ReadFile (introduced in Go1.16) which is much shorter
than the previous patterns and doesn't leak resources.

Fixes #89
  • Loading branch information
odeke-em authored Apr 3, 2024
1 parent 49eaeac commit 53ca3de
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package app
import (
"encoding/json"
"fmt"
"io"
"os"
"time"

Expand Down Expand Up @@ -212,13 +211,11 @@ func loadLocales() map[string]map[string]string {
translations[locale] = make(map[string]string)
file := fmt.Sprintf("./locales/%s.json", locale)

jsonFile, err := os.Open(file)
byteValue, err := os.ReadFile(file)
if err != nil {
log.Fatal(err)
}

byteValue, _ := io.ReadAll(jsonFile)

var result map[string]interface{}
json.Unmarshal([]byte(byteValue), &result)

Expand Down

0 comments on commit 53ca3de

Please sign in to comment.