gosora/common/menu_item_store.go
Azareal 1c0a3dd5b6 Accept shorter session param names as these are so common.
Prealloc in DefaultPollStore.BulkGetMap
Shorten more variable names.
Remove a bit of inline CSS in topic_alt_quick_reply
2019-07-27 08:36:06 +10:00

31 lines
535 B
Go

package common
import "sync"
type DefaultMenuItemStore struct {
items map[int]MenuItem
lock sync.RWMutex
}
func NewDefaultMenuItemStore() *DefaultMenuItemStore {
return &DefaultMenuItemStore{
items: make(map[int]MenuItem),
}
}
func (s *DefaultMenuItemStore) Add(item MenuItem) {
s.lock.Lock()
defer s.lock.Unlock()
s.items[item.ID] = item
}
func (s *DefaultMenuItemStore) Get(id int) (MenuItem, error) {
s.lock.RLock()
item, ok := s.items[id]
s.lock.RUnlock()
if ok {
return item, nil
}
return item, ErrNoRows
}