[GoLang] Adding FeatureFlags using github repo
--
What is feature flag?
There is a post by Martin Fowler on feature flag, and can be found here.
In our last post: Self-Updating binaries for Go, we utilized the github platform to add a functionality in our go application for self update, and today, we will add one more tool in our arsenal of using powerful feature-flags
by storing a file in github-repo.
Problem statement: Now, we have developed an application with rich of features, however, we want to test new features for a specific set of users before rolling out for everyone.
Premium services: There are paid services that provide this feature out of the box, like the configcat, launchdarkly, etc.
Opensource solution: gofeatureflag, sourcecode: github
How to use the go-feature-flag?
- Let’s start with an empty project. Source code for the project
2. Initialize the go-feature-flag module using the below command:
go get github.com/thomaspoignant/go-feature-flag
3. Now, we need a github repo to host the flag file, which sets the feature values to enable or disable for the set of users. Below is an example of the sample flag YAML file
new-admin-access:
variations:
default_var: false
false_var: false
true_var: true
defaultRule:
percentage:
false_var: 20
true_var: 80
flag-only-for-admin:
variations:
default_var: false
false_var: false
true_var: true
targeting:
- query: admin eq true
percentage:
false_var: 0
true_var: 100
defaultRule:
variation: Default
The code for whole repository can be download from here: