Example #1
0
// Update an item if the value is not changed.
func (ks *InMemoryStorage) UpdateValueIfEqual(obj *storage.MetaDataUpdObj) error {
	if obj != nil {
		if len(obj.Key) == 0 {
			return errors.New("Object key is null.")
		}
		if len(obj.Collection) == 0 {
			obj.Collection = "default"
		}
		obj.CreationDate = time.Now()
		if ks.collection.UpdateValueIfEqual(obj) {
			return nil
		} else {
			return errors.New("Objects are not equal.")
		}
	}
	return errors.New("Object is null.")
}
Example #2
0
// Change the key of an item.
func (ks *InMemoryStorage) UpdateKey(obj *storage.MetaDataUpdObj) error {
	if obj != nil {
		if len(obj.Key) == 0 {
			return errors.New("Object key is null.")
		}
		if len(obj.NewKey) == 0 {
			return errors.New("Object new key is null.")
		}
		if len(obj.Collection) == 0 {
			obj.Collection = "default"
		}
		obj.CreationDate = time.Now()
		ks.collection.UpdateKey(obj)
		return nil
	}
	return errors.New("Object is null.")
}