Getting started with Go SDK
On this page
This section describes how to set up and install the Go SDK and how to deploy a feature flag.
Step 1 - Setting up
To setup Go SDK, follow these steps:
-
Create a CloudBees Feature Management account. See Signup Page to create an account.
-
Get your environment key.
-
Get the key from App Settings > Environment > Key.
-
Add the CloudBees Feature Management Go package to your application
To add the CloudBees Feature Management Go library to your project, run the following command:
# Add the SDK to your project
$go get -u github.com/rollout/rox-go/...
Add the following lines of code to your project
package main
// Import the SDK
import "github.com/rollout/rox-go/server"
import "fmt"
// Create Roxflags in the Flags container class
type Flags struct {
EnableTutorial server.RoxFlag
TitleColors server.RoxVariant
}
var flags = & Flags {
// Define the feature flags
EnableTutorial: server.NewRoxFlag(false),
TitleColors: server.NewRoxVariant("Green", [] string {"White", "Blue", "Green", "Yellow"}),
}
var rox * server.Rox
func main() {
options := server.NewRoxOptions(server.RoxOptionsBuilder {})
rox := server.NewRox()
// Register the flags container
rox.Register("", flags)
// Setup the environment key
<-rox.Setup("<ROLLOUT-ENV-KEY>", options)
// Boolean flag example
if (flags.EnableTutorial.IsEnabled(nil)) {
// TODO: Put your code here that needs to be gated
}
// Multivariate flag example
fmt.Println("TitleColors is " + flags.TitleColors.GetValue(nil))
}
Container class registration and environment key setup
|