Skip to content

cloudbees-io/gin-fm-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gin application example

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.

Prerequisites

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)

Clone the example repository

git clone https://github.com/cloudbees-io/gin-fm-example.git
cd gin-fm-example

Open the app in your editor

Open 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.

Copy the SDK key

  1. In the CloudBees platform UI, navigate to Feature management.

  2. Retrieve the SDK key

    1. Select Installation instructions in the upper right corner.

    2. 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.

    3. Select Go as the SDK language. (This step generates a unique SDK key.)

    4. 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.

Replace the SDK key in main.go

Back in your editor, open the main.go file.

  1. In the main.go file, find the sdkKey := "<YOUR-SDK-KEY>" line and paste in the newly generated SDK key, replacing the placeholder value:

    sdkKey := "your-sdk-key-here"
  2. Check the main.go file to ensure the following lines are included:

Ensure the fmt package is imported at the top of the file:
import "fmt"
Also ensure the following lines inside the same initFlags() function to confirm successful flag registration:
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))

Install the Go SDK

In the terminal, inside the gin-fm-example folder run the following:

go get -u github.com/rollout/rox-go/v5/...

Run the application

In the terminal, run the following command:

go run main.go

You should see:

Listening and serving HTTP on :8080

Open the app in your browser

Copy 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!"
}

Confirm SDK connection in the UI

Back in the CloudBees platform:

  1. Return to the Feature management > Installation instructions page.

  2. Select Test integration at the bottom of the instructions page.

  3. You should see a success message indicating the SDK is connected.

Modify and test flags

Next you will modify a flag configuration and observe the change in the browser.

  1. On the Feature management > Flags page.

  2. Choose your application (for example, goAppTest).

  3. Select the ShowMessage flag and set it to true.

  4. Modify optional flags:

    • message (custom string such as "Hello summer")

    • fontColor (red, green, blue)

    • fontSize (12, 16, 24)

  5. Select Save configuration.

  6. Set Configuration status to On.

  7. Refresh http://localhost:8080/demo to see your changes reflected.

Troubleshooting

Symptom Fix

No flags appear

Ensure the correct SDK key is added and saved in main.go.

"No SDK connection detected"

Refresh /demo and re-test integration in the UI.

Terminal shows 404 errors

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages