-
Notifications
You must be signed in to change notification settings - Fork 16
Closed
Description
When working with feature flags, it's sometimes necessary to access the original feature flag key buried inside the generated code.
Here are some examples:
- In our test cases, we use environment variables to control flags, and we have to duplicate the feature flag name to mimic the uppercase'd underscored mapping ("FEATURE_MY_FEATURE").
- For prometheus, you have to set up the valid metrics at initialization time, well before evaluating any metrics
- You might also provide command-line flags to set features. For those you need information about (at least) the name of the flag.
It would be great if the generated code had the ability to access this original string, without having to e.g. evaluate the flag.
In go, it could be something like this:
// stringer transforms a string to a Stringer
type stringer string
// String implements the fmt.Stringer interface
func (s stringer) String() string {
return string(s)
}
var MyCoolFeature = struct {
fmt.Stringer
Value BooleanProvider
ValueWithDetails BooleanProviderDetails
}{
Stringer: stringer("my-cool-feature"),
Value: func(ctx context.Context, evalCtx openfeature.EvaluationContext) (bool, error) {
return client.BooleanValue(ctx, "my-cool-feature", false, evalCtx)
},
ValueWithDetails: func(ctx context.Context, evalCtx openfeature.EvaluationContext) (openfeature.BooleanEvaluationDetails, error) {
return client.BooleanValueDetails(ctx, "my-cool-feature", false, evalCtx)
},
}
The caller can then know the original key of a provider by stringing it.
MyCoolFeature.String()
And from there, we could do things like craft environment variables, or command line flags.
kriscoleman
Metadata
Metadata
Assignees
Labels
No labels