-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstore.go
More file actions
37 lines (31 loc) · 811 Bytes
/
store.go
File metadata and controls
37 lines (31 loc) · 811 Bytes
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
package cachestore
import (
"errors"
"github.com/fsm/fsm"
)
// New returns an instance of a cacheStore
func New() fsm.Store {
return &cacheStore{
traversers: make(map[string]fsm.Traverser, 0),
}
}
type cacheStore struct {
traversers map[string]fsm.Traverser
}
func (s *cacheStore) FetchTraverser(uuid string) (fsm.Traverser, error) {
if traverser, ok := s.traversers[uuid]; ok {
return traverser, nil
}
return nil, errors.New("Traverser does not exist")
}
func (s *cacheStore) CreateTraverser(uuid string) (fsm.Traverser, error) {
if _, ok := s.traversers[uuid]; ok {
return nil, errors.New("Traverser with UUID already exists")
}
traverser := &cachedTraverser{
Data: make(map[string]interface{}, 0),
}
traverser.SetUUID(uuid)
s.traversers[uuid] = traverser
return traverser, nil
}