I am currently working on a task and I am stuck. We use unleash and have default, development and production environment but we only use default. While connecting to unleash using golang, we don’t specify the environment.
I have to change it such that we can connect for different environments and use it for testing.
I found this function .withEnvironment in unleash go client which can be used to set environment.
err := unleash.Initialize(
unleash.WithAppName("appName"),
unleash.WithListener(&unleashListener.CustomListener{}),
unleash.WithUrl(url),
unleash.WithCustomHeaders(http.Header{"Authorization": {authToken}}),
unleash.WithStrategies(&strategy.<StrategyName>{}),
unleash.WithEnvironment(env),
)
I have a strategy in default with which I am testing and I have no strategies in development environment. I made an api call which would use unleash to make call 1 if unleash configuration is enabled and make call 2 if it’s not.
Now, because while connecting, I set the environment as development, it should have made call 2 because there is no strategy in development let alone the strategy for which we are checking at that point.
I’m not sure why this is happening.
I also saw that when we are checking if the strategy is enabled or not, in context, we can also setup environment and while running a debugger, it’s completely skipping the environment part.
func featureToggle(userID int64, language string) bool {
bucketId := userID % 100
ctx := unleashContext.Context{
Environment: "development",
Properties: map[string]string{
"bucketId": strconv.FormatInt(int64(bucketId), 10),
"language": language,
},
}
return unleash.IsEnabled("project.featureToggle", unleash.WithContext(ctx))
}
I’m not sure how to do this. Can someone help me with this?
Tried setting environment while creating a connection to unleash
Tried setting environment in the feature toggle context