ducky/devices

Paddy 2015-11-28 Parent:683050b4546b Child:1ae5bae472c1

12:03c49b4d3d9f Go to Latest

ducky/devices/memstore.go

Add doc comments to all our exported types. It makes golint happy, and it's a good thing to do. It's kind of shameful that we went so long without them. Oops.

History
     1.1 --- a/memstore.go	Fri Nov 27 11:32:15 2015 -0800
     1.2 +++ b/memstore.go	Sat Nov 28 18:26:03 2015 -0800
     1.3 @@ -7,17 +7,29 @@
     1.4  	"golang.org/x/net/context"
     1.5  )
     1.6  
     1.7 +// Memstore is an in-memory implementation of Storer, and should
     1.8 +// only be used for testing or for temporary local servers.
     1.9  type Memstore struct {
    1.10  	devices map[string]Device
    1.11  	lock    sync.RWMutex
    1.12  }
    1.13  
    1.14 +// NewMemstore returns a Memstore that is ready to be used as a
    1.15 +// Storer implementation.
    1.16  func NewMemstore() *Memstore {
    1.17  	return &Memstore{
    1.18  		devices: map[string]Device{},
    1.19  	}
    1.20  }
    1.21  
    1.22 +// GetDevices returns any Devices in the Memstore that match the
    1.23 +// passed IDs. If an ID cannot be matched to a Device in the
    1.24 +// Memstore, it is ignored. The result is a map, with the values
    1.25 +// being the Devices that could be found, and the keys being the
    1.26 +// result of the String() method for each Device's ID.
    1.27 +//
    1.28 +// An empty map is a possible response, if none of the IDs could
    1.29 +// be found.
    1.30  func (m *Memstore) GetDevices(ids []uuid.ID, c context.Context) (map[string]Device, error) {
    1.31  	m.lock.RLock()
    1.32  	defer m.lock.RUnlock()
    1.33 @@ -34,6 +46,11 @@
    1.34  	return results, nil
    1.35  }
    1.36  
    1.37 +// UpdateDevice applies the passed DeviceChange to the Device
    1.38 +// in the Memstore specified by the DeviceChange's DeviceID
    1.39 +// property. If no Device in the Memstore matches the DeviceChange's
    1.40 +// DeviceID property, then an ErrDeviceNotFound error will be
    1.41 +// returned.
    1.42  func (m *Memstore) UpdateDevice(change DeviceChange, c context.Context) error {
    1.43  	m.lock.Lock()
    1.44  	defer m.lock.Unlock()
    1.45 @@ -49,10 +66,17 @@
    1.46  	return nil
    1.47  }
    1.48  
    1.49 +// DeleteDevices will remove any Devices from the Memstore that match
    1.50 +// the IDs passed in. If an ID can't be matched to a Device in the
    1.51 +// Memstore, then it is ignored.
    1.52  func (m *Memstore) DeleteDevices(id []uuid.ID, c context.Context) error {
    1.53  	return nil
    1.54  }
    1.55  
    1.56 +// CreateDevices stores the passed devices in the Memstore as a single
    1.57 +// transaction. If a Device's ID already exists in the Memstore, an
    1.58 +// ErrDeviceAlreadyExists error with that Device's ID is returned, and
    1.59 +// none of the passed Devices are stored.
    1.60  func (m *Memstore) CreateDevices(devices []Device, c context.Context) error {
    1.61  	m.lock.Lock()
    1.62  	defer m.lock.Unlock()
    1.63 @@ -69,6 +93,11 @@
    1.64  	return nil
    1.65  }
    1.66  
    1.67 +// ListDevicesByOwner returns all the Devices in the Memstore that have an
    1.68 +// Owner property that matches the passed ID. If no Devices have an Owner
    1.69 +// property matching the passed ID, an empty slice is returned.
    1.70 +//
    1.71 +// ListDevicesByOwner does not guarantee any sort order for the Devices.
    1.72  func (m *Memstore) ListDevicesByOwner(user uuid.ID, c context.Context) ([]Device, error) {
    1.73  	var devices []Device
    1.74  	for _, device := range m.devices {