ducky/subscriptions

Paddy 2015-10-04 Parent:1ff031bebf9e

16:b063bc0a6e84 Go to Latest

ducky/subscriptions/memstore.go

Make api subpackage golint-passing. Add comments to all the exported functions, methods, and variables in the api subpackage, to make golint happy. Also, make the individual endpoints in the api subpackage unexported, as there's no real use case for exporting them. The handlers depend on the placeholders in the endpoint, so we need them to be controlled in unison, which means it's probably a bad idea to declare the route outside of the API package. And the only reason to expose the Handler is so people can declare custom endpoints.

History
paddy@0 1 package subscriptions
paddy@0 2
paddy@0 3 import (
paddy@0 4 "sync"
paddy@0 5 )
paddy@0 6
paddy@0 7 // Memstore is an in-memory version of our datastores, useful
paddy@0 8 // for testing. It should not be used in production.
paddy@0 9 type Memstore struct {
paddy@0 10 subscriptions map[string]Subscription
paddy@0 11 subscriptionLock sync.RWMutex
paddy@0 12 }
paddy@0 13
paddy@0 14 // NewMemstore returns a pointer to a Memstore object, ready
paddy@0 15 // to be used as a datastore.
paddy@0 16 func NewMemstore() *Memstore {
paddy@0 17 return &Memstore{
paddy@0 18 subscriptions: map[string]Subscription{},
paddy@0 19 }
paddy@0 20 }
paddy@0 21
paddy@13 22 // Reset empties all the data from the Memstore. It should only
paddy@13 23 // be used in tests.
paddy@3 24 func (m *Memstore) Reset() error {
paddy@0 25 m.subscriptionLock.Lock()
paddy@0 26 defer m.subscriptionLock.Unlock()
paddy@0 27
paddy@0 28 m.subscriptions = map[string]Subscription{}
paddy@0 29 return nil
paddy@0 30 }