コード例 #1
0
ファイル: features.go プロジェクト: lacion/feature-flags
// 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
}
コード例 #2
0
ファイル: features.go プロジェクト: lacion/feature-flags
// 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)
	})
}