Skip to content

Commit 243e7f2

Browse files
committed
feature management quickstarts in go scenario
1 parent 37b94ba commit 243e7f2

File tree

7 files changed

+595
-0
lines changed

7 files changed

+595
-0
lines changed

articles/azure-app-configuration/TOC.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,16 @@
8181
href: quickstart-go-console-app.md
8282
- name: Dynamic configuration
8383
href: enable-dynamic-configuration-go-console-app.md
84+
- name: Feature management
85+
href: quickstart-feature-flag-go-console.md
8486
- name: Go Gin
8587
items:
8688
- name: Configuration
8789
href: quickstart-go-web-app.md
8890
- name: Dynamic configuration
8991
href: enable-dynamic-configuration-gin-web-app.md
92+
- name: Feature management
93+
href: quickstart-feature-flag-go-gin.md
9094
- name: Azure Functions
9195
items:
9296
- name: Configuration
@@ -431,6 +435,10 @@
431435
items:
432436
- name: Feature reference
433437
href: ./feature-management-javascript-reference.md
438+
- name: Go
439+
items:
440+
- name: Feature reference
441+
href: https://pkg.go.dev/github.com/microsoft/Featuremanagement-Go/featuremanagement
434442
- name: Telemetry
435443
items:
436444
- name: Feature flag telemetry reference

articles/azure-app-configuration/index.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ landingContent:
151151
url: quickstart-feature-flag-python.md
152152
- text: Node.js app
153153
url: quickstart-feature-flag-javascript.md
154+
- text: Go console app
155+
url: quickstart-feature-flag-go-console.md
156+
- text: Go Gin web app
157+
url: quickstart-feature-flag-go-gin.md
154158
- linkListType: tutorial
155159
links:
156160
- text: Enable conditional features with feature filters
@@ -179,6 +183,8 @@ landingContent:
179183
url: https://microsoft.github.io/FeatureManagement-Python/html/index.html
180184
- text: JavaScript feature management
181185
url: feature-management-javascript-reference.md
186+
- text: Go feature management
187+
url: https://pkg.go.dev/github.com/microsoft/Featuremanagement-Go/featuremanagement
182188

183189
- title: Client libraries and tools
184190
linkLists:
29.8 KB
Loading
27.6 KB
Loading
25.2 KB
Loading
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
---
2+
title: Quickstart for adding feature flags to Go console apps
3+
titleSuffix: Azure App Configuration
4+
description: Learn to implement feature flags in your Go console application using feature management and Azure App Configuration. Dynamically manage feature rollouts and control feature visibility without redeploying the app.
5+
services: azure-app-configuration
6+
author: linglingye
7+
ms.service: azure-app-configuration
8+
ms.devlang: golang
9+
ms.topic: quickstart
10+
ms.custom: devx-track-go, mode-other
11+
ms.date: 07/03/2025
12+
ms.author: linglingye
13+
#Customer intent: As a Go developer, I want to use feature flags to control feature availability quickly and confidently.
14+
---
15+
16+
# Quickstart: Add feature flags to a Go console app
17+
18+
In this quickstart, you'll create a feature flag in Azure App Configuration and use it to dynamically control the availability of features in a Go console app.
19+
20+
The feature management support extends the dynamic configuration feature in App Configuration. This example demonstrates how to integrate feature flags into a Go console application with real-time monitoring capabilities.
21+
22+
## Prerequisites
23+
24+
- An Azure account with an active subscription. [Create one for free](https://azure.microsoft.com/free/).
25+
- An App Configuration store. [Create a store](./quickstart-azure-app-configuration-create.md#create-an-app-configuration-store).
26+
- Go 1.18 or later. For information on installing Go, see the [Go downloads page](https://golang.org/dl/).
27+
- [Azure App Configuration Go provider](https://pkg.go.dev/github.com/Azure/AppConfiguration-GoProvider/azureappconfiguration) v1.1.0-beta.1 or later.
28+
29+
## Create a feature flag
30+
31+
Add a feature flag called *Beta* to the App Configuration store and leave **Label** and **Description** with their default values. For more information about how to add feature flags to a store using the Azure portal or the CLI, go to [Create a feature flag](./manage-feature-flags.md#create-a-feature-flag).
32+
33+
> [!div class="mx-imgBorder"]
34+
> ![Enable feature flag named Beta](./media/add-beta-feature-flag.png)
35+
36+
## Use a feature flag
37+
38+
1. Create a new directory for your Go project and navigate into it:
39+
40+
```console
41+
mkdir go-feature-flag-quickstart
42+
cd go-feature-flag-quickstart
43+
```
44+
45+
1. Initialize a new Go module:
46+
47+
```console
48+
go mod init go-feature-flag-quickstart
49+
```
50+
51+
1. Install the required Go packages for Azure App Configuration and feature management:
52+
53+
```console
54+
go get github.com/Azure/AppConfiguration-GoProvider/azureappconfiguration
55+
go get github.com/microsoft/Featuremanagement-Go/featuremanagement
56+
go get github.com/microsoft/Featuremanagement-Go/featuremanagement/providers/azappconfig
57+
```
58+
59+
1. Update the `options` to enable feature flags in [previous step](./quickstart-go-console-app.md#connect-to-app-configuration).
60+
61+
```golang
62+
options := &azureappconfiguration.Options{
63+
FeatureFlagOptions: azureappconfiguration.FeatureFlagOptions{
64+
Enabled: true,
65+
RefreshOptions: azureappconfiguration.RefreshOptions{
66+
Enabled: true,
67+
},
68+
},
69+
}
70+
```
71+
72+
> [!TIP]
73+
> When no selector is specified in `FeatureFlagOptions`, it loads *all* feature flags with *no label* in your App Configuration store. The default refresh interval of feature flags is 30 seconds. You can customize this behavior via the `RefreshOptions` parameter. For example, the following code snippet loads only feature flags that start with *TestApp:* in their *key name* and have the label *dev*. The code also changes the refresh interval time to 5 minutes. Note that this refresh interval time is separate from that for regular key-values.
74+
>
75+
> ```golang
76+
> FeatureFlagOptions{
77+
> Enabled: true,
78+
> Selectors: []azureappconfiguration.Selector{
79+
> {
80+
> KeyFilter: "TestApp:*",
81+
> LabelFilter: "dev",
82+
> },
83+
> },
84+
> RefreshOptions: azureappconfiguration.RefreshOptions{
85+
> Enabled: true,
86+
> Interval: 5 * time.Minute,
87+
> },
88+
> }
89+
> ```
90+
91+
1. Create the main application file `main.go`:
92+
93+
```golang
94+
package main
95+
96+
import (
97+
"context"
98+
"fmt"
99+
"log"
100+
"os"
101+
"time"
102+
103+
"github.com/microsoft/Featuremanagement-Go/featuremanagement"
104+
"github.com/microsoft/Featuremanagement-Go/featuremanagement/providers/azappconfig"
105+
)
106+
107+
func main() {
108+
ctx := context.Background()
109+
110+
// Load Azure App Configuration
111+
appConfig, err := loadAzureAppConfiguration(ctx)
112+
if err != nil {
113+
log.Fatalf("Error loading Azure App Configuration: %v", err)
114+
}
115+
116+
// Create feature flag provider
117+
featureFlagProvider, err := azappconfig.NewFeatureFlagProvider(appConfig)
118+
if err != nil {
119+
log.Fatalf("Error creating feature flag provider: %v", err)
120+
}
121+
122+
// Create feature manager
123+
featureManager, err := featuremanagement.NewFeatureManager(featureFlagProvider, nil)
124+
if err != nil {
125+
log.Fatalf("Error creating feature manager: %v", err)
126+
}
127+
128+
// Monitor the Beta feature flag
129+
fmt.Println("Monitoring 'Beta' feature flag (press Ctrl+C to exit):")
130+
fmt.Println("Toggle the Beta feature flag in Azure portal to see real-time updates...")
131+
fmt.Println()
132+
133+
ticker := time.NewTicker(5 * time.Second)
134+
defer ticker.Stop()
135+
136+
for {
137+
select {
138+
case <-ticker.C:
139+
// Refresh configuration to get latest feature flag settings
140+
if err := appConfig.Refresh(ctx); err != nil {
141+
log.Printf("Error refreshing configuration: %v", err)
142+
continue
143+
}
144+
145+
// Evaluate the Beta feature flag
146+
isEnabled, err := featureManager.IsEnabled("Beta")
147+
if err != nil {
148+
log.Printf("Error checking if Beta feature is enabled: %v", err)
149+
continue
150+
}
151+
152+
// Print timestamp and feature status
153+
timestamp := time.Now().Format("15:04:05")
154+
fmt.Printf("[%s] Beta is enabled: %t\n", timestamp, isEnabled)
155+
156+
case <-ctx.Done():
157+
fmt.Println("\nShutting down...")
158+
return
159+
}
160+
}
161+
}
162+
```
163+
164+
## Run the application
165+
166+
1. Run the application:
167+
168+
```console
169+
go run main.go
170+
```
171+
---
172+
173+
1. The application will start monitoring the *Beta* feature flag and display its current state every 5 seconds:
174+
175+
```console
176+
Monitoring 'Beta' feature flag (press Ctrl+C to exit):
177+
Toggle the Beta feature flag in Azure portal to see real-time updates...
178+
179+
[14:30:15] Beta is enabled: false
180+
[14:30:20] Beta is enabled: false
181+
[14:30:25] Beta is enabled: false
182+
```
183+
184+
1. Sign in to the [Azure portal](https://portal.azure.com). Select **All resources**, and select the App Configuration store that you created previously.
185+
186+
1. Select **Feature manager** and locate the *Beta* feature flag. Enable the flag by selecting the checkbox under **Enabled**.
187+
188+
1. Return to your console application. After a few seconds, you should see the feature flag status change:
189+
190+
```console
191+
[14:30:30] Beta is enabled: false
192+
[14:30:35] Beta is enabled: true
193+
[14:30:40] Beta is enabled: true
194+
```
195+
196+
1. You can toggle the feature flag on and off in the Azure portal to see real-time updates in your console application without restarting it.
197+
198+
1. Press **Ctrl+C** to stop the application.
199+
200+
## Clean up resources
201+
202+
[!INCLUDE[Azure App Configuration cleanup](../../includes/azure-app-configuration-cleanup.md)]
203+
204+
## Next steps
205+
206+
In this quickstart, you created a feature flag in Azure App Configuration and used it in a Go console application. The [Feature Management Go library](https://github.com/microsoft/FeatureManagement-Go) provides rich feature flag capabilities that integrate seamlessly with Azure App Configuration. For more features, continue to the following document.
207+
208+
> [!div class="nextstepaction"]
209+
> [Go Feature Management reference](https://pkg.go.dev/github.com/microsoft/Featuremanagement-Go/featuremanagement)
210+
211+
While a feature flag allows you to activate or deactivate functionality in your app, you may want to customize a feature flag based on your app's logic. Feature filters allow you to enable a feature flag conditionally. For more information, continue to the following tutorial.
212+
213+
> [!div class="nextstepaction"]
214+
> [Enable conditional features with feature filters](./howto-feature-filters.md)
215+
216+
Azure App Configuration offers built-in feature filters that enable you to activate a feature flag only during a specific period or to a particular targeted audience of your app. For more information, continue to the following tutorial.
217+
218+
> [!div class="nextstepaction"]
219+
> [Enable features on a schedule](./howto-timewindow-filter.md)
220+
221+
> [!div class="nextstepaction"]
222+
> [Roll out features to targeted audiences](./howto-targetingfilter.md)
223+

0 commit comments

Comments
 (0)