GitLab Feature Flags

  • It looks like GitLab now has feature flags available for the free users (at least on the hosted version). This is a pretty awesome free feature. Here's an example of how to leverage it.

    First create your feature flag:

    I opted to leave the bottom section of user specific flags alone.

    Then make sure to get your config:


    Then all you need to do is enable it in your application:

    package main
    import (
    type metricsInterface struct {
    func init() {
    	environment := os.Getenv("APP_ENVIRONMENT")
    func main() {
    	if unleash.IsEnabled("test") {
    		fmt.Println("This is the app with the feature flag on.")
    	} else {
    		fmt.Println("This is the app with the feature flag off.")

    So that's fairly self explanatory. We import the unleash library and then initialize unleash with the URL, instance ID, and environment. I opted to use an environment variable to define the app's environment. If the environment was "Production" the flag wouldn't even be used and would default to off. Then in your code, just include the name of the specific flag where you want to enable or disable a feature. Then when you enable or disable the flag in GitLab it will enable or disable the feature in your app. It goes without saying that your app will need internet access for this to work unless you're self hosting. Then you would just need LAN access. You can have multiple flags for one app, so just use the correct flag name in your code at the appropriate areas.

  • To be clear, GitLab uses Unleash for their feature flags which is open source. It also has it's own UI, but it's nice to have it in your code base and not need to run a separate server.