Skip to content

Commit c459c0e

Browse files
authored
chore: add helper to access feature flags (#349)
1 parent ac8a7e8 commit c459c0e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package config_utils
22

33
import (
4+
"net/http"
5+
46
"github.com/snyk/go-application-framework/internal/api"
57
"github.com/snyk/go-application-framework/pkg/configuration"
68
"github.com/snyk/go-application-framework/pkg/workflow"
@@ -12,19 +14,19 @@ func AddFeatureFlagToConfig(engine workflow.Engine, configKey string, featureFla
1214
callback := func(existingValue interface{}) (interface{}, error) {
1315
if existingValue == nil {
1416
httpClient := engine.GetNetworkAccess().GetHttpClient()
15-
logger := engine.GetLogger()
16-
url := config.GetString(configuration.API_URL)
17-
org := config.GetString(configuration.ORGANIZATION)
18-
apiClient := api.NewApi(url, httpClient)
19-
result, err := apiClient.GetFeatureFlag(featureFlagName, org)
20-
if err != nil {
21-
logger.Printf("Failed to determine feature flag \"%s\" for org \"%s\": %s", featureFlagName, org, err)
22-
}
23-
return result, nil
17+
return GetFeatureFlagValue(featureFlagName, config, httpClient)
2418
} else {
2519
return existingValue, nil
2620
}
2721
}
2822

2923
config.AddDefaultValue(configKey, callback)
3024
}
25+
26+
func GetFeatureFlagValue(featureFlagName string, config configuration.Configuration, httpClient *http.Client) (bool, error) {
27+
url := config.GetString(configuration.API_URL)
28+
org := config.GetString(configuration.ORGANIZATION)
29+
apiClient := api.NewApi(url, httpClient)
30+
result, err := apiClient.GetFeatureFlag(featureFlagName, org)
31+
return result, err
32+
}

0 commit comments

Comments
 (0)