Skip to content

Commit

Permalink
Merge pull request #1 from RobinToubi/fix_path
Browse files Browse the repository at this point in the history
fix: set countries.json path depending on GOPATH environment variable to fetch correctly the data.
  • Loading branch information
RobinToubi authored Jun 15, 2023
2 parents aec949e + c6afa95 commit 1eb9dce
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions countries.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io/ioutil"
"path/filepath"
)

type CountryData struct {
Expand All @@ -21,17 +20,16 @@ type Country struct {

func InstanceCountry() *CountryData {
instance := &CountryData{}
instance = instance.readCountriesFile()
instance = instance.ReadCountriesFile()

return instance
}

func (data *CountryData) readCountriesFile() *CountryData {
func (data *CountryData) ReadCountriesFile() *CountryData {
if len(data.countries) > 0 {
return data
}
filePath, _ := filepath.Abs("./countries.json")
file, err := ioutil.ReadFile(filePath)
file, err := ioutil.ReadFile("countries.json")
if err != nil {
return nil
}
Expand Down

0 comments on commit 1eb9dce

Please sign in to comment.