Taobin-Recipe-Manager/server/data/data.go
Kenta420-Poom 8a6dc19bdd init Project ✌️✌️
2023-09-14 14:52:04 +07:00

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{})
}