init Project ✌️✌️
This commit is contained in:
commit
8a6dc19bdd
42 changed files with 249179 additions and 0 deletions
47
server/data/data.go
Normal file
47
server/data/data.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
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{})
|
||||
}
|
||||
236126
server/data/data.json
Normal file
236126
server/data/data.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue