Go SDK installation

2 minute read

Control feature rollout for certain user segments of your application with feature flags. To start using feature management in the platform, follow the instructions below to install the SDK and deploy a feature flag.

Install the SDK

Follow these steps to install the SDK:

  1. Select Feature management  Installation.

  2. Select an Environment from the options, or create an environment by completing the following:

    1. Select Create environment.

    2. Enter an Environment name.

    3. (Optional) Enter a Description.

    4. (Optional) Select Approvers if you want to have a manual approval required before deployment.

    5. (Optional) Enter any Properties you want to associate with the environment. For more information, refer to properties configuration and properties in an environment.

    6. Select Submit.

  3. Select Go from the language options, and the package manager Get is selected by default.

  4. Add the ROX package to your application by running the shell command appropriate for the package manager:

    go get -u github.com/rollout/rox-go/v6/...
  5. Add the following code to your Go application:

    Your SDK key is a unique environment identifier. During SDK installation, the SDK key is displayed within the Rox.setup call.
    package main import ( "fmt" "github.com/rollout/rox-go/v6/server" ) // Define the feature flags in the Flags container type Flags struct { EnableTutorial server.RoxFlag } func main() { // Initialize the Flags container with default flag values flags := &Flags{ EnableTutorial: server.NewRoxFlag(false), } // Create a new Rox instance rox := server.NewRox() // Register the flags container with the Rox instance rox.Register("", flags) // Setup the Rox instance with your environment key errChan := rox.Setup("<YOUR-SDK-KEY>", server.NewRoxOptions(server.RoxOptionsBuilder{})) (1) // Wait for the setup to complete if err := <-errChan; err != nil { fmt.Printf("Error during Rox setup: %v\n", err) return } // Example usage of the feature flag if flags.EnableTutorial.IsEnabled(nil) { fmt.Println("Tutorial is enabled.") } else { fmt.Println("Tutorial is disabled.") } // Shutdown the Rox instance gracefully rox.Shutdown() }
    1 The platform provides the unique SDK key for your environment at the <YOUR-SDK-KEY> location within the Rox.setup call.

Run the application and test the integration

Follow these steps to test the integration:

  1. Run your application.

  2. In the CloudBees platform, select Test integration to verify the SDK connection.

After running the application, flags added in the code are automatically added to your feature flag list.

You have installed an SDK and created flags in your application.

Refer to the SDK reference for more information.
Download the code for link: an example Gin application with feature flags.