Create internal/thestore/event.Store and getter, setter
This commit is contained in:
BIN
render-2023-10-11/internal/thestore/.store.go.swp
Normal file
BIN
render-2023-10-11/internal/thestore/.store.go.swp
Normal file
Binary file not shown.
24
render-2023-10-11/internal/thestore/store.go
Normal file
24
render-2023-10-11/internal/thestore/store.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package thestore
|
||||
|
||||
import "sync"
|
||||
|
||||
type Store sync.Map
|
||||
|
||||
func NewStore() *Store {
|
||||
s := sync.Map{}
|
||||
store := Store(s)
|
||||
return &store
|
||||
}
|
||||
|
||||
func (store *Store) Set(k string, v Event) {
|
||||
(*sync.Map)(store).Store(k, v)
|
||||
}
|
||||
|
||||
func (store *Store) Get(k string) (Event, bool) {
|
||||
got, ok := (*sync.Map)(store).Load(k)
|
||||
if !ok {
|
||||
return Event{}, false
|
||||
}
|
||||
event := got.(Event)
|
||||
return event, true
|
||||
}
|
||||
Reference in New Issue
Block a user