This example is for use with CloudBees platform, feature management.
Use this guide to connect the gin-fm-example Go application to your CloudBees platform feature management environment. Once connected, you can apply changes to feature flags, and observe the flag changes in your browser, http://localhost:8080/demo.
Be sure to have these requirements ready:
-
A CloudBees SaaS platform account: https://cloudbees.io
-
An existing or new Feature Management environment
-
Go installed on your local machine
-
Recommended: Go 1.20+ for macOS ARM64 (Apple M1/Pro)
-
git clone https://github.com/cloudbees-io/gin-fm-example.git
cd gin-fm-exampleOpen the cloned repository in the gin-fm-example folder. If you’re using VS Code and the code command is installed, use the following in the terminal:
code .Or open main.go in your preferred editor manually.
-
In the CloudBees platform UI, navigate to Feature management.
-
Retrieve the SDK key
-
Select Installation instructions in the upper right corner.
-
Follow the guided steps to:
-
Create or select an environment (for example,
goEnvTest). -
Create or select an application (for example,
goAppTest). -
Link the application to the environment.
-
-
Select Go as the SDK language. (This step generates a unique SDK key.)
-
In the code block, on the right side of the screen, copy the newly generated SDK key.
-
|
Note
|
You will come back to the Installation instructions page once the key is successfully saved and run in the main.go file in the Go app.
|
Back in your editor, open the main.go file.
-
In the
main.gofile, find thesdkKey := "<YOUR-SDK-KEY>"line and paste in the newly generated SDK key, replacing the placeholder value:sdkKey := "your-sdk-key-here"
-
Check the
main.gofile to ensure the following lines are included:
import "fmt"fmt.Println("ROX SDK setup complete. Forcing flag registration:")
fmt.Println("showMessage:", flags.ShowMessage.IsEnabled(nil))
fmt.Println("message:", flags.Message.GetValue(nil))
fmt.Println("fontColor:", flags.FontColor.GetValue(nil))
fmt.Println("fontSize:", flags.FontSize.GetValue(nil))In the terminal, inside the gin-fm-example folder run the following:
go get -u github.com/rollout/rox-go/v5/...In the terminal, run the following command:
go run main.goYou should see:
Listening and serving HTTP on :8080Copy the following and paste it into a browser window:
http://localhost:8080/demo
You’ll see JSON output with flag-controlled values similar to:
{
"fontColor": "Green",
"fongSize": 12,
"message": "Hello summer!"
}Back in the CloudBees platform:
-
Return to the Feature management > Installation instructions page.
-
Select Test integration at the bottom of the instructions page.
-
You should see a success message indicating the SDK is connected.
Next you will modify a flag configuration and observe the change in the browser.
-
On the Feature management > Flags page.
-
Choose your application (for example, goAppTest).
-
Select the
ShowMessageflag and set it to true. -
Modify optional flags:
-
message(custom string such as "Hello summer") -
fontColor(red, green, blue) -
fontSize(12, 16, 24)
-
-
Select Save configuration.
-
Set Configuration status to On.
-
Refresh
http://localhost:8080/demoto see your changes reflected.
| Symptom | Fix |
|---|---|
No flags appear |
Ensure the correct SDK key is added and saved in |
"No SDK connection detected" |
Refresh |
Terminal shows |
Ensure the SDK key is valid and internet connection is stable. |
Changes to a flag is not showing in the browser. |
Make sure the flag’s configuration status is set to On. |
Cannot edit files in VS Code |
Confirm file permissions are not set to read-only. |