update getting file recipe
This commit is contained in:
parent
ea506b8128
commit
3bfbbd778a
10 changed files with 243 additions and 152 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"recipe-manager/models"
|
||||
"sort"
|
||||
|
|
@ -28,23 +29,28 @@ func ReadFile(filePath string) (string, error) {
|
|||
return string(file), nil
|
||||
}
|
||||
|
||||
func ReadRecipeFile(filePath string) models.Recipe {
|
||||
file, err := os.Open(filePath)
|
||||
func ReadRecipeFile(countryID, filePath string) *models.Recipe {
|
||||
|
||||
if countryID == "thai" {
|
||||
countryID = ""
|
||||
}
|
||||
|
||||
file, err := os.Open(path.Join("cofffeemachineConfig", countryID, filePath))
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Error when open file: %s", err)
|
||||
return models.Recipe{}
|
||||
return nil
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
var data models.Recipe
|
||||
var data *models.Recipe
|
||||
|
||||
err = json.NewDecoder(file).Decode(&data)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Error when decode file: %s", err)
|
||||
return models.Recipe{}
|
||||
return nil
|
||||
}
|
||||
|
||||
return data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue