47 lines
698 B
Go
47 lines
698 B
Go
package data
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
func readFile() map[string]interface{} {
|
|
file, err := os.Open("data/data.json")
|
|
|
|
if err != nil {
|
|
log.Fatalf("Error when open file: %s", err)
|
|
return nil
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
var data map[string]interface{}
|
|
|
|
err = json.NewDecoder(file).Decode(&data)
|
|
|
|
if err != nil {
|
|
log.Fatalf("Error when decode file: %s", err)
|
|
return nil
|
|
}
|
|
|
|
return data
|
|
}
|
|
|
|
type Data struct {
|
|
recipe map[string]interface{}
|
|
}
|
|
|
|
func NewData() *Data {
|
|
return &Data{
|
|
recipe: readFile(),
|
|
}
|
|
}
|
|
|
|
func (d *Data) GetRecipe() map[string]interface{} {
|
|
return d.recipe
|
|
}
|
|
|
|
func (d *Data) GetRecipe01() []interface{} {
|
|
return d.recipe["Recipe01"].([]interface{})
|
|
}
|