SimpleFeatureFlags provides a simple way to enable or disable features, per-environment, using application configuration.
def compute_pi() do
if SimpleFeatureFlags.enabled?(:new_algorithm) do
compute_pi_new_algorithm()
else
3.14
end
end
config/runtime.exs
...
config :simple_feature_flags, :flags, %{
...
features: %{
new_algorithm: %{enabled_in: [:localhost, :staging]}
...
}
...
}
...
lib/myapp/application.ex
defmodule MyApp.Application do
require Logger
use Application
@impl true
def start(_type, _args) do
Logger.info(SimpleFeatureFlags.current_configuration_to_string())
children =
...
Here is an example of the output:
Current Deployment Environment: :test
Features:
- new_algorithm, enabled in [:localhost, :staging]
- new_ui, enabled in [:localhost]
config/runtime.exs
...
config :simple_feature_flags, :flags, %{
current_deployment_environment: :test,
features: %{
new_algorithm: %{enabled_in: [:localhost, :staging]},
new_ui: %{enabled_in: [:localhost]}
}
}
...
To turn a feature or or off, update configuration and restart your application. For example, to enable the new_algorithm
feature in production, add :production
to the list of enabled_in
:
...
new_algorithm: %{enabled_in: [:localhost, :staging, :production]}
...
The package can be installed by adding simple_feature_flags
to your list of dependencies in mix.exs
:
def deps do
[
{:simple_feature_flags, "~> 0.1"}
]
end
The docs can be found at https://hexdocs.pm/simple_feature_flags.