func (c *Client) Set(ft *models.Feature) error { defer c.Store.Close() var existing *models.Feature kvb, err := c.Store.Get(ft.ScopedKey()) if err != nil { return err } if kvb != nil { err = json.Unmarshal(kvb.Bytes, &existing) if err != nil { return err } } if err != nil { return err } if existing != nil { if ft.Comment == "" { ft.Comment = existing.Comment } if ft.Value == nil { ft.Value = existing.Value } if ft.FeatureType != existing.FeatureType && ft.FeatureType != "" { return ErrTypeChange } if ft.FeatureType == "" { ft.FeatureType = existing.FeatureType } } else { if ft.Value == nil { return ErrNilValue } } bts, err := ft.ToJSON() if err != nil { return err } err = c.Store.Set(ft.ScopedKey(), bts) if err != nil { return err } err = c.SendStatEvent(ft, false) return nil }
func NewMockStore(ft *models.Feature, err error) (ms *MockStore) { bts, _ := ft.ToJSON() ms = &MockStore{ Err: err, } if ft != nil { kvb := KVBytes{ &KVByte{ Key: ft.Key, Bytes: bts, }, } ms.Item = kvb[0] ms.Items = kvb } return }