diff --git a/server/country.settings.json b/server/country.settings.json new file mode 100644 index 0000000..f2a0d5d --- /dev/null +++ b/server/country.settings.json @@ -0,0 +1,28 @@ +[ + { + "name": "Thailand", + "short": "tha", + "permissions": 1 + }, + { + "name": "Malaysia", + "short": "mys", + "permissions": 2 + }, + { + "name": "Australia", + "short": "aus", + "permissions": 4 + }, + { + "name": "Alpha3", + "short": "alpha-3", + "permissions": 8 + }, + { + "ignore": true, + "name": "New Country in full name", + "short": "Short name", + "permissions": "use number after 128, do not use 16 and 128" + } +] \ No newline at end of file diff --git a/server/data/data.go b/server/data/data.go index eef8028..682b279 100644 --- a/server/data/data.go +++ b/server/data/data.go @@ -186,9 +186,42 @@ var ( } ) +func LoadCountrySettings() []helpers.CountryName { + res := make([]helpers.CountryName, 0) + + // read file country.settings.json + content, err := os.Open("country.settings.json") + if err != nil { + fmt.Errorf("country.settings.json not found") + } + + // read content to json + var countrySettings []map[string]interface{} + err = json.NewDecoder(content).Decode(&countrySettings) + + if err != nil { + fmt.Errorf("error in country.settings") + return nil + } + + for _, v := range countrySettings { + if ignore, ok := v["ignore"].(bool); ok { + if ignore { + continue + } + } + res = append(res, helpers.CountryName{ + CountryID: v["short"].(string), + CountryName: v["name"].(string), + }) + } + + return res +} + func NewData(taoLogger *logger.TaoLogger, redisClient *RedisCli) *Data { - allRecipeFiles := helpers.ScanRecipeFiles(countries) + allRecipeFiles := helpers.ScanRecipeFiles(LoadCountrySettings()) defaultFile := "coffeethai02_600.json"