open-feature / go-sdk-contrib

Community maintained OpenFeature Providers and Hooks for Go
https://openfeature.dev
Apache License 2.0
42 stars 38 forks source link

Env provider option for mapping flag names #526

Closed morigs closed 2 months ago

morigs commented 2 months ago

Most shells doesn't allow env variables with dashes. Also, by convention, environment variables should be uppercased and words separated by underscores. However, feature flags no always following this convention. When you want to switch between multiple providers easily (and I believe this is one of the OpenFeature targets) your flags should have the same name in all providers, which is not the case for the env provider.

Perhaps this could be solved by providing a mapper function as a provider option. This mapper could map requested flag name into environment variable name. Configuration solutions like viper and koanf already follow this approach for environment variable providers and it works fine

Kavindu-Dodan commented 2 months ago

I like the proposal of the mapper and #528 implementation looks good

toddbaert commented 2 months ago

This is a needed feature, and we actually have similar features in other env providers.