|
| 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) |
0 commit comments