GO Feature Flag is a simple, complete and lightweight self-hosted cloud native feature flag solution 100% Open Source — built on OpenFeature ️
GO Feature Flag is a simple, complete and lightweight self-hosted cloud native feature flag solution 100% Open Source — built on OpenFeature ️
<a href="https://github.com/avelino/awesome-go/#server-applications"></a>
<a href="https://gofeatureflag.org/slack"></a>
<a href="https://github.com/sponsors/thomaspoignant"></a>
<br />
<a href="https://gofeatureflag.org">GO Feature Flag is a simple, complete and lightweight self-hosted cloud native feature flag solution 100% Open Source. ️</a>
:pray: If you are using GO Feature Flag please consider to add yourself in the adopters list.
This simple act significantly boosts the project's visibility and credibility, making a substantial contribution to its advancement.If you want to support me and GO Feature Flag, you can also become a sponsor.
GO Feature Flag is a lightweight and open-source solution that provides a simple and complete feature flag implementation.
The solution has been built to facilitate the usage of feature flags in your code with the easiest setup possible.
Originally, GO Feature Flag was designed as a solution exclusively for the GO language. With the new standardization of feature flags by the Openfeature project, the solution is now available for multiple languages (list of supported languages) through a simple API server called the relay proxy, which can be hosted.
[!TIP] If you are not familiar with feature flags, I've written an article which explains why feature flags can fasten your iteration cycle.
HTTP, S3, Kubernetes, see full list).JSON, TOML and YAML).S3, Google cloud storage, file, Kafka, see the full list).webhook and slack).https://github.com/user-attachments/assets/56e1a2a2-996f-4db8-9c93-28c057e4ed5a
The code of this demo is available in examples/demo repository.
At GO Feature Flag, we believe in the power of open standards and, the importance of vendor neutrality. That's why we've chosen to rely on Open Feature for our SDKs.
By adopting GO Feature Flag you embrace the OpenFeature standard and you get all the benefits of the ecosystem.
Using Open Feature SDKs[!IMPORTANT] Before starting to use GO Feature Flag you should decide if you want to use Open Feature SDKs or if you want to use GO Feature Flag as a GO Module.
We recommend using the relay-proxy for a central flag management and evaluation solution, it enables the multi-languages support, and it integrates seamlessly with the Open Feature SDKs.
This is the best way to get full potential of GO Feature Flag.If your project is exclusively in GO, the GO module is an option. It will perform the flag evaluation directly in your GO code.
Create a new YAML file containing your first flag configuration.
# 20% of the users will use the variation "my-new-feature"
test-flag:
variations:
my-new-feature: true
my-old-feature: false
defaultRule:
percentage:
my-new-feature: 20
my-old-feature: 80This flag split the usage of this flag, 20% will use the variation my-new-feature and 80% the variation my-old-feature.
Create a new YAML file containing the configuration of your relay proxy.
server:
mode: http
port: 1031
pollingInterval: 1000
startWithRetrieverError: false
retriever:
kind: file
path: /goff/flag-config.yaml
exporter:
kind: logAnd we will run the relay proxy locally to make the API available.
The default port will be 1031.
# Launch the container
docker run \
-p 1031:1031 \
-v $(pwd)/flag-config.yaml:/goff/flag-config.yaml \
-v $(pwd)/goff-proxy.yaml:/goff/goff-proxy.yaml \
gofeatureflag/go-feature-flag:latest
If you don't want to use docker to install the relay proxy you can follow other ways to install it in the documentation.
In this example, we are using the nodejs SDK, but you can check other languages here.
npm i @openfeature/server-sdk @openfeature/go-feature-flag-providerIn your app initialization, you have to create a client using the Open Feature SDK and initialize it.
const {OpenFeature} = require("@openfeature/server-sdk");
const {GoFeatureFlagProvider} = require("@openfeature/go-feature-flag-provider");
// init Open Feature SDK with GO Feature Flag provider
const goFeatureFlagProvider = new GoFeatureFlagProvider({
endpoint: 'http://localhost:1031/' // DNS of your instance of relay proxy
});
OpenFeature.setProvider(goFeatureFlagProvider);
const featureFlagClient = OpenFeature.getClient('my-app')Now you can evaluate your flags anywhere in your code using this client.
…go get github.com/thomaspoignant/go-feature-flagCreate a new YAML file containing your first flag configuration.
# 20% of the users will use the variation "my-new-feature"
test-flag:
variations:
my-new-feature: true
my-old-feature: false
defaultRule:
percentage:
my-new-feature: 20
my-old-feature: 80This flag split the usage of this flag, 20% will use the variation my-new-feature and 80% the variation my-old-feature.
First, you need to initialize the ffclient with the location of your backend file.
err := ffclient.Init(ffclient.Config{
PollingInterval: 3 * time.Second,
Retriever: &fileretriever.Retriever{
Path: "flag-config.goff.yaml",
},
})
defer ffclient.Close()This example will load a file from your local computer and will refresh the flags every 3 seconds (if you omit the PollingInterval, the default value is 60 seconds).
ℹ info
This is a basic configuration to test locally, in production it is better to use a remote place to store your feature flag configuration file.
Look at the list of available options in the Store your feature flag file page.
Now you can evaluate your flags anywhere in your code.
user := ffcontext.NewEvaluationContext("user-unique-key")
hasFlag, _ := ffclient.BoolVariation("test-flag", user, false)
if hasFlag {
// flag "test-flag" is true for the user
} else {
// flag "test-flag" is false for the user
}The full documentation is available on https://docs.gofeatureflag.org
You can find more examples in the examples/ directory.
Originally GO Feature Flag was built to be a GOlang only library, but it limits the ecosystem too much.
To be compatible with more languages we have implemented the GO Feature Flag Relay Proxy.
It is a service you can host that provides an API to evaluate your flags, you can call it using HTTP to get your variation.
Since we believe in standardization we are also implementing OpenFeature providers to interact with this API in the language of your choice.
_(OpenFeature is still at an early stage, so not all languages are supported
No open issues yet, or sync has not completed.