2018-05-11 05:41:51 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import "sync"
|
|
|
|
|
|
|
|
type DefaultMenuItemStore struct {
|
2022-02-21 03:32:53 +00:00
|
|
|
items map[int]MenuItem
|
|
|
|
lock sync.RWMutex
|
2018-05-11 05:41:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewDefaultMenuItemStore() *DefaultMenuItemStore {
|
2022-02-21 03:32:53 +00:00
|
|
|
return &DefaultMenuItemStore{
|
|
|
|
items: make(map[int]MenuItem),
|
|
|
|
}
|
2018-05-11 05:41:51 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 06:56:51 +00:00
|
|
|
func (s *DefaultMenuItemStore) Add(i MenuItem) {
|
2022-02-21 03:32:53 +00:00
|
|
|
s.lock.Lock()
|
|
|
|
defer s.lock.Unlock()
|
|
|
|
s.items[i.ID] = i
|
2018-05-11 05:41:51 +00:00
|
|
|
}
|
|
|
|
|
2019-07-26 22:36:06 +00:00
|
|
|
func (s *DefaultMenuItemStore) Get(id int) (MenuItem, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
s.lock.RLock()
|
|
|
|
item, ok := s.items[id]
|
|
|
|
s.lock.RUnlock()
|
|
|
|
if ok {
|
|
|
|
return item, nil
|
|
|
|
}
|
|
|
|
return item, ErrNoRows
|
2018-05-11 05:41:51 +00:00
|
|
|
}
|