knowyt/server/src/game/game.go

30 lines
445 B
Go
Raw Normal View History

2021-08-04 22:12:28 +00:00
package game
import (
"encoding/json"
"fmt"
"os"
)
func NewGameFromFile(fileName string) (*Game, error) {
jsonBytes, err := os.ReadFile(fileName)
if err != nil {
return nil, err
}
var gm Game
if err := json.Unmarshal(jsonBytes, &gm); err != nil {
return nil, fmt.Errorf("%s: %v\n", fileName, err)
} else {
return &gm, nil
}
}
2021-08-04 22:40:31 +00:00
func (gm *Game) SetId(id string) {
gm.id = id
}
func (gm *Game) GetId() string {
return gm.id
}