Skip to content

A Gitlab Feature flags client that can be used to easily check flags status from your projects.

Notifications You must be signed in to change notification settings

Pho3b/gitlab-ff-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Feature Flags Client

The purpose of this project is to expose an interface to use the Gitlab Feature-Flags feature across one Gitlab specific group of repositories.
Feature-Flags is a Gitlab integrated system that gives the possibility to dynamically Toggle features in live environments.

Initialization

  • The FeatureFlags client mu be initialized before it can be used. This is typically done in your application's initialization phase.
// Initialize the ffclient keeping the default configurations
ffclient.Init(YourProjectUrl, YourProjectId) 

// Or, initialize it with custom configurations
ffclient.InitWithConfig(config.ClientConfig{
    // Project URL and ProjectId can be found in your giltab repository [Deploy -> Feature flags] section
    // clicking on the 'Configure' button.
    ProjectUrl                  "https://foo.gitlab.com"
    ProjectId                   "1234"
    Logger:              myCustomLogger, 
    EnvironmentType:     enums.Staging, 
    EnvironmentTypeVariableName: "MY_ENV_TYPE",
    ValidEnvironmentTypes       []enums.EnvType
    AsyncInitialization         false
})

Usage:

  • After initialization, you can obtain the client instance using the Get function:
ffclient := ffclient.Get()
  • Check if a feature is enabled without User context:
isEnabled := ffclient.Get().IsFeatureEnabled(featureflags.SpecificUserFlag)

if isEnabled {
    // Feature is enabled, proceed with feature logic
} else {
    // Feature is disabled, handle disabled state
}
  • Check if a feature is enabled for a specific User.
isEnabled := ffclient.Get().IsFeatureEnabledForUser(featureflags.SpecificUserFlag, "user@docebo.com")

if isEnabled {
    // Feature is enabled for the specific user, proceed with feature logic
} else {
    // Feature is disabled for the user or globally, handle disabled state
}

Additional Notes

  • This library tries by default to retrieve the environment type (Production, Staging, Development, etc.) from the EnvTypeVariableName environment variable if the EnvType is not explicitly passed through in the configurations. You can configure the environment variable name and type by using the ffclient.InitWithConfig function.
// An example of how to set the default Environment variable in order to send the Gitlab environment property as Development
os.Setenv(constants.EnvTypeVariableName, enums.Development.ToString())

About

A Gitlab Feature flags client that can be used to easily check flags status from your projects.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Languages