Skip to content

Commit 8a1001d

Browse files
authored
Merge pull request #303300 from linglingye001/go/fm/timewindow
Go Gin web app in time window scenario
2 parents c429e22 + 5a57275 commit 8a1001d

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

articles/azure-app-configuration/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@
208208
href: howto-timewindow-filter-aspnet-core.md
209209
- name: JavaScript
210210
href: howto-timewindow-filter-javascript.md
211+
- name: Go Gin
212+
href: howto-timewindow-filter-go.md
211213
- name: Python
212214
href: howto-time-window-filter-python.md
213215
- name: Roll out features to targeted audience
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
title: Enable features on a schedule in a Go Gin web application
3+
titleSuffix: Azure App Configuration
4+
description: Learn how to enable feature flags on a schedule in a Go Gin web application by using time window filters.
5+
ms.service: azure-app-configuration
6+
ms.devlang: golang
7+
author: linglingye
8+
ms.author: linglingye
9+
ms.topic: how-to
10+
ms.custom: devx-track-go, mode-other
11+
ms.date: 07/25/2025
12+
---
13+
14+
# Enable features on a schedule in a Go Gin web application
15+
16+
In this guide, you use the time window filter to enable a feature on a schedule for a Go Gin web application.
17+
18+
The example used in this article is based on the Go Gin web application introduced in the feature management [quickstart](./quickstart-feature-flag-go-gin.md). Before proceeding further, complete the quickstart to create a Go Gin web application with a *Beta* feature flag. Once completed, you must [add a time window filter](./howto-timewindow-filter.md) to the *Beta* feature flag in your App Configuration store.
19+
20+
## Prerequisites
21+
22+
- Create a [Go Gin web application with a feature flag](./quickstart-feature-flag-go-gin.md).
23+
- [Add a time window filter to the feature flag](./howto-timewindow-filter.md)
24+
25+
## Use the time window filter
26+
27+
You added a time window filter for your *Beta* feature flag in the prerequisites. Next, you'll use the feature flag with the time window filter in your Go Gin web application.
28+
29+
When you create a feature manager, the built-in feature filters are automatically added to its feature filter collection
30+
31+
The existing code from the quickstart already handles time window filters through the feature manager:
32+
33+
```golang
34+
// Create feature flag provider
35+
featureFlagProvider, err := azappconfig.NewFeatureFlagProvider(appConfig)
36+
if err != nil {
37+
log.Fatalf("Error creating feature flag provider: %v", err)
38+
}
39+
40+
// Create feature manager (supports built-in filters including TimeWindowFilter)
41+
featureManager, err := featuremanagement.NewFeatureManager(featureFlagProvider, nil)
42+
if err != nil {
43+
log.Fatalf("Error creating feature manager: %v", err)
44+
}
45+
```
46+
47+
The feature evaluation in your middleware will now respect the time window filter:
48+
49+
```golang
50+
func (app *WebApp) featureMiddleware() gin.HandlerFunc {
51+
return func(c *gin.Context) {
52+
// Check if Beta feature is enabled (TimeWindowFilter is automatically evaluated)
53+
betaEnabled, err := app.featureManager.IsEnabled("Beta")
54+
if err != nil {
55+
log.Printf("Error checking Beta feature: %v", err)
56+
}
57+
58+
// Store feature flag status for use in templates
59+
c.Set("betaEnabled", betaEnabled)
60+
c.Next()
61+
}
62+
}
63+
```
64+
65+
## Time window filter in action
66+
67+
Relaunch the application. If your current time is earlier than the start time set for the time window filter, the **Beta** menu item won't appear on the toolbar. This is because the *Beta* feature flag is disabled by the time window filter.
68+
69+
:::image type="content" source="./media/quickstarts/gin-app-feature-flag-before.png" alt-text="Screenshot of Gin web app with Beta menu hidden.":::
70+
71+
Once the start time has passed, refresh your browser a few times. You'll notice that the **Beta** menu item now appears. This is because the *Beta* feature flag is now enabled by the time window filter.
72+
73+
:::image type="content" source="./media/quickstarts/gin-app-feature-flag-after.png" alt-text="Screenshot of Gin web app with Beta menu.":::
74+
75+
## Next steps
76+
77+
To learn more about the feature filters, continue to the following documents.
78+
79+
> [!div class="nextstepaction"]
80+
> [Enable conditional features with feature filters](./howto-feature-filters.md)
81+
82+
> [!div class="nextstepaction"]
83+
> [Roll out features to targeted audience](./howto-targetingfilter.md)
84+
85+
For the full feature rundown of the Go feature management library, continue to the following document.
86+
87+
> [!div class="nextstepaction"]
88+
> [Go Feature Management reference](https://pkg.go.dev/github.com/microsoft/Featuremanagement-Go/featuremanagement)

articles/azure-app-configuration/howto-timewindow-filter.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ In this article, you learn how to add and configure a time window filter for you
5858

5959
- [ASP.NET Core](./howto-timewindow-filter-aspnet-core.md)
6060
- [JavaScript](./howto-timewindow-filter-javascript.md)
61+
- [Go Gin](./howto-timewindow-filter-go.md)
6162
- [Python](./howto-time-window-filter-python.md)
6263

6364
## Next steps

0 commit comments

Comments
 (0)