-
Notifications
You must be signed in to change notification settings - Fork 0
/
local.go
48 lines (38 loc) · 849 Bytes
/
local.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package storage
import (
"errors"
"github.com/l12u/gamemaster/internal/model"
)
type LocalProvider struct {
games model.GameMap
}
func NewLocalProvider() *LocalProvider {
return &LocalProvider{
games: make(model.GameMap),
}
}
func (l *LocalProvider) PutGame(g *model.Game) error {
if g == nil {
return errors.New("game can not be nil")
}
l.games[g.Id] = g
return nil
}
func (l *LocalProvider) GetGame(id string) (*model.Game, error) {
return l.games[id], nil
}
func (l *LocalProvider) GetAllGames() (model.GameMap, error) {
return l.games, nil
}
func (l *LocalProvider) DeleteGame(id string) error {
delete(l.games, id)
return nil
}
func (l *LocalProvider) ClearGames() error {
l.games = make(model.GameMap)
return nil
}
func (l *LocalProvider) HasGame(id string) (bool, error) {
_, ok := l.games[id]
return ok, nil
}