grafana/pkg/setting/setting_feature_toggles.go
Serge Zaitsev aebcecf538
Chore: Fix goimports grouping in other backend platform packages (#62422)
* fix goimports

* fix goimports order

* fix goimports order

* fix goimports order

* fix goimports order

* fix goimports order
2023-01-30 08:26:42 +00:00

47 lines
1.2 KiB
Go

package setting
import (
"strconv"
"gopkg.in/ini.v1"
"github.com/grafana/grafana/pkg/util"
)
// @deprecated -- should use `featuremgmt.FeatureToggles`
func (cfg *Cfg) readFeatureToggles(iniFile *ini.File) error {
section := iniFile.Section("feature_toggles")
toggles, err := ReadFeatureTogglesFromInitFile(section)
if err != nil {
return err
}
cfg.IsFeatureToggleEnabled = func(key string) bool { return toggles[key] }
return nil
}
func ReadFeatureTogglesFromInitFile(featureTogglesSection *ini.Section) (map[string]bool, error) {
featureToggles := make(map[string]bool, 10)
// parse the comma separated list in `enable`.
featuresTogglesStr := valueAsString(featureTogglesSection, "enable", "")
for _, feature := range util.SplitString(featuresTogglesStr) {
featureToggles[feature] = true
}
// read all other settings under [feature_toggles]. If a toggle is
// present in both the value in `enable` is overridden.
for _, v := range featureTogglesSection.Keys() {
if v.Name() == "enable" {
continue
}
b, err := strconv.ParseBool(v.Value())
if err != nil {
return featureToggles, err
}
featureToggles[v.Name()] = b
}
return featureToggles, nil
}