-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeature_flags.go
45 lines (36 loc) · 1.11 KB
/
feature_flags.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package feature_flags
import (
"fmt"
"github.com/go-coldbrew/feature-flags/config"
"github.com/go-coldbrew/feature-flags/engines"
"github.com/go-coldbrew/feature-flags/engines/unleash"
)
var Client engines.FeatureFlag
const (
EngineUnleash = "unleash"
)
// Initialize initializes an engines.FeatureFlag instance, return error if failed
func Initialize(appName string, cfg config.Config) error {
var err error
switch cfg.FeatureFlagEngine {
case EngineUnleash:
Client, err = unleash.Initialize(appName, cfg.UnleashConfig)
return err
default:
return fmt.Errorf("unsupported feature flag engine: %s", cfg.FeatureFlagEngine)
}
}
// IsEnabled check if a feature flag is enabled, returns false if client is not initialized
func IsEnabled(name string, ctx engines.Context) bool {
if Client == nil {
return false
}
return Client.IsEnabled(name, ctx)
}
// GetVariant get variant for a feature flag, returns disabled variant if client is not initialised
func GetVariant(name string, ctx engines.Context) *engines.Variant {
if Client == nil {
return engines.DisabledVariant
}
return Client.GetVariant(name, ctx)
}