Example #1
0
// Update a feature flag
func (interactor *FeatureService) UpdateFeature(featureKey string, newFeature m.FeatureFlag) (feature m.FeatureFlag, err error) {
	_ = interactor.DB.Update(func(tx *bolt.Tx) error {

		if feature, err = repos.GetFeature(tx, featureKey); err != nil {
			return err
		}

		feature.Enabled = newFeature.Enabled

		if len(newFeature.Users) > 0 {
			feature.Users = newFeature.Users
		}

		if len(newFeature.Groups) > 0 {
			feature.Groups = newFeature.Groups
		}

		if newFeature.Percentage > 0 {
			feature.Percentage = newFeature.Percentage
		}

		return repos.PutFeature(tx, feature)
	})

	return
}
Example #2
0
// Get a single feature flag thanks to its key
func (interactor *FeatureService) GetFeature(featureKey string) (feature m.FeatureFlag, err error) {
	_ = interactor.DB.View(func(tx *bolt.Tx) error {

		feature, err = repos.GetFeature(tx, featureKey)
		return err
	})

	return
}
Example #3
0
// Store a new feature flag in the database
func (interactor *FeatureService) AddFeature(newFeature m.FeatureFlag) error {
	return interactor.DB.Update(func(tx *bolt.Tx) error {

		feature, err := repos.GetFeature(tx, newFeature.Key)
		if err != nil && err.Error() != "Unable to find feature" {
			return err
		}

		if len(feature.Key) > 0 {
			return fmt.Errorf("Feature already exists")
		}

		return repos.PutFeature(tx, newFeature)
	})
}