This example demonstrates how to use the refresh functionality of Azure App Configuration in a console/command-line application.
This console application:
- Loads configuration values from Azure App Configuration
- Binds them to target configuration struct
- Automatically refreshes the configuration when changed in Azure App Configuration
You need an Azure subscription and the following Azure resources to run the examples:
The examples retrieve credentials to access your App Configuration store from environment variables.
Add the following key-values to the App Configuration store and leave Label and Content Type with their default values:
| Key | Value |
|---|---|
| Config.Message | Hello World! |
| Config.Font.Color | blue |
| Config.Font.Size | 12 |
-
Initialize a new Go module.
go mod init console-example-refresh
-
Add the Azure App Configuration provider as a dependency.
go get github.com/Azure/AppConfiguration-GoProvider/azureappconfiguration
-
Set the connection string as an environment variable:
# Windows set AZURE_APPCONFIG_CONNECTION_STRING=your-connection-string # Linux/macOS export AZURE_APPCONFIG_CONNECTION_STRING=your-connection-string
go run main.go- Start the application
- While it's running, modify the values in your Azure App Configuration store
- Within 10 seconds (the configured refresh interval), the application should detect and apply the changes
- You don't need to restart the application to see the updated values