Documentation
¶
Overview ¶
Package azureappconfiguration provides a client for Azure App Configuration, enabling Go applications to manage application settings with Microsoft's Azure App Configuration service.
The azureappconfiguration package allows loading configuration data from Azure App Configuration in a structured way, with support for automatic Key Vault reference resolution, hierarchical configuration construction, and strongly typed configuration binding.
For more information about Azure App Configuration, see: https://learn.microsoft.com/en-us/azure/azure-app-configuration/
Index ¶
- type AuthenticationOptions
- type AzureAppConfiguration
- func (azappcfg *AzureAppConfiguration) GetBytes(options *ConstructionOptions) ([]byte, error)
- func (azappcfg *AzureAppConfiguration) OnRefreshSuccess(callback func())
- func (azappcfg *AzureAppConfiguration) Refresh(ctx context.Context) error
- func (azappcfg *AzureAppConfiguration) Unmarshal(v any, options *ConstructionOptions) error
- type ConstructionOptions
- type FeatureFlagOptions
- type KeyValueRefreshOptions
- type KeyVaultOptions
- type Options
- type RefreshOptions
- type SecretResolver
- type Selector
- type WatchedSetting
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthenticationOptions ¶
type AuthenticationOptions struct { // Credential is a token credential for Azure EntraID Authentication. // Required when Endpoint is provided. Credential azcore.TokenCredential // Endpoint is the URL of the Azure App Configuration service. // Required when using token-based authentication with Credential. Endpoint string // ConnectionString is the connection string for the Azure App Configuration service. ConnectionString string }
AuthenticationOptions contains parameters for authenticating with the Azure App Configuration service. Either a connection string or an endpoint with credential must be provided.
type AzureAppConfiguration ¶
type AzureAppConfiguration struct {
// contains filtered or unexported fields
}
An AzureAppConfiguration is a configuration provider that stores and manages settings sourced from Azure App Configuration.
func Load ¶
func Load(ctx context.Context, authentication AuthenticationOptions, options *Options) (*AzureAppConfiguration, error)
Load initializes a new AzureAppConfiguration instance and loads the configuration data from Azure App Configuration service.
Parameters:
- ctx: The context for the operation.
- authentication: Authentication options for connecting to the Azure App Configuration service
- options: Configuration options to customize behavior, such as key filters and prefix trimming
Returns:
- A configured AzureAppConfiguration instance that provides access to the loaded configuration data
- An error if the operation fails, such as authentication errors or connectivity issues
func (*AzureAppConfiguration) GetBytes ¶
func (azappcfg *AzureAppConfiguration) GetBytes(options *ConstructionOptions) ([]byte, error)
GetBytes returns the configuration as a JSON byte array with hierarchical structure. This method is particularly useful for integrating with "encoding/json" package or third-party configuration packages like Viper or Koanf.
Parameters:
- options: Optional parameters for controlling JSON construction, particularly the key separator
Returns:
- A byte array containing the JSON representation of the configuration
- An error if JSON marshalling fails or if an invalid separator is specified
func (*AzureAppConfiguration) OnRefreshSuccess ¶
func (azappcfg *AzureAppConfiguration) OnRefreshSuccess(callback func())
OnRefreshSuccess registers a callback function that will be executed whenever the configuration is successfully refreshed and actual changes were detected.
Multiple callback functions can be registered, and they will be executed in the order they were added. Callbacks are only executed when configuration values actually change. They run synchronously in the thread that initiated the refresh.
Parameters:
- callback: A function with no parameters that will be called after a successful refresh
func (*AzureAppConfiguration) Refresh ¶
func (azappcfg *AzureAppConfiguration) Refresh(ctx context.Context) error
Refresh manually triggers a refresh of the configuration from Azure App Configuration. It checks if any watched settings have changed, and if so, reloads all configuration data.
The refresh only occurs if:
- Refresh has been configured with RefreshOptions when the client was created
- The configured refresh interval has elapsed since the last refresh
- No other refresh operation is currently in progress
If the configuration has changed, any callback functions registered with OnRefreshSuccess will be executed.
Parameters:
- ctx: The context for the operation.
Returns:
- An error if refresh is not configured, or if the refresh operation fails
func (*AzureAppConfiguration) Unmarshal ¶
func (azappcfg *AzureAppConfiguration) Unmarshal(v any, options *ConstructionOptions) error
Unmarshal parses the configuration and stores the result in the value pointed to v. It builds a hierarchical configuration structure based on key separators. It supports converting values to appropriate target types.
Fields in the target struct are matched with configuration keys using the field name by default. For custom field mapping, use json struct tags.
Parameters:
- v: A pointer to the struct to populate with configuration values
- options: Optional parameters (e,g, separator) for controlling the unmarshalling behavior
Returns:
- An error if unmarshalling fails due to type conversion issues or invalid configuration
type ConstructionOptions ¶
type ConstructionOptions struct { // Separator specifies the character used to determine hierarchy in configuration keys // when mapping to nested struct fields during unmarshaling operations. // Supported values: '.', ',', ';', '-', '_', '__', '/', ':'. // If not provided, the default separator "." will be used. Separator string }
ConstructionOptions contains parameters for parsing keys with hierarchical structure.
type FeatureFlagOptions ¶ added in v1.1.0
type FeatureFlagOptions struct { // Enabled specifies whether feature flags will be loaded from Azure App Configuration. Enabled bool // If no selectors are provided, all feature flags with no label will be loaded when enabled feature flags. Selectors []Selector // RefreshOptions specifies the behavior of feature flags refresh. // Refresh interval must be greater than 1 second. If not provided, the default interval 30 seconds will be used // All loaded feature flags will be automatically watched when feature flags refresh is enabled. RefreshOptions RefreshOptions }
FeatureFlagOptions contains optional parameters for Azure App Configuration feature flags that will be parsed and transformed into feature management configuration.
type KeyValueRefreshOptions ¶
type KeyValueRefreshOptions struct { // WatchedSettings specifies the key-value settings to watch for changes WatchedSettings []WatchedSetting // Interval specifies the minimum time interval between consecutive refresh operations for the watched settings // Must be greater than 1 second. If not provided, the default interval 30 seconds will be used Interval time.Duration // Enabled specifies whether the provider should automatically refresh when the configuration is changed. Enabled bool }
KeyValueRefreshOptions contains optional parameters to configure the behavior of key-value settings refresh
type KeyVaultOptions ¶
type KeyVaultOptions struct { // Credential specifies the token credential used to authenticate to Azure Key Vault services. // This is required for Key Vault reference resolution unless a custom SecretResolver is provided. Credential azcore.TokenCredential // SecretResolver specifies a custom implementation for resolving Key Vault references. // When provided, this takes precedence over using the default resolver with Credential. SecretResolver SecretResolver // RefreshOptions specifies the behavior of Key Vault secrets refresh. // Sets the refresh interval for periodically reloading secrets from Key Vault, must be greater than 1 minute. RefreshOptions RefreshOptions }
KeyVaultOptions contains parameters to configure the build-in Key Vault reference resolution. These options determine how the provider will authenticate with and retrieve
type Options ¶
type Options struct { // TrimKeyPrefixes specifies a list of prefixes to trim from the keys of all key-values // retrieved from Azure App Configuration, making them more suitable for binding to structured types. TrimKeyPrefixes []string // Selectors defines what key-values to load from Azure App Configuration // Each selector combines a key filter and label filter // If selectors are not provided, all key-values with no label are loaded by default. Selectors []Selector // RefreshOptions contains optional parameters to configure the behavior of key-value settings refresh RefreshOptions KeyValueRefreshOptions // KeyVaultOptions configures how Key Vault references are resolved. KeyVaultOptions KeyVaultOptions // FeatureFlagOptions contains optional parameters for Azure App Configuration feature flags. FeatureFlagOptions FeatureFlagOptions // ClientOptions provides options for configuring the underlying Azure App Configuration client. ClientOptions *azappconfig.ClientOptions // ReplicaDiscoveryEnabled specifies whether to enable replica discovery for the Azure App Configuration service. // It defaults to true, which allows the provider to discover and use replicas for improved availability. ReplicaDiscoveryEnabled *bool // LoadBalancingEnabled specifies whether to enable load balancing across multiple replicas of the Azure App Configuration service. // It defaults to false. LoadBalancingEnabled bool }
Options contains optional parameters to configure the behavior of an Azure App Configuration provider. It provides control over which key-values to fetch, how to trim key prefixes, and how to handle Key Vault references.
type RefreshOptions ¶
type RefreshOptions struct { // Interval specifies the minimum time interval between consecutive refresh operations Interval time.Duration // Enabled specifies whether the provider should automatically refresh when data is changed. Enabled bool }
RefreshOptions contains optional parameters to configure the behavior of refresh
type SecretResolver ¶
type SecretResolver interface { // ResolveSecret resolves a Key Vault reference URL to the actual secret value. // // Parameters: // - ctx: The context for the operation // - keyVaultReference: A URL in the format "https://{keyVaultName}.vault.azure.net/secrets/{secretName}/{secretVersion}" // // Returns: // - The resolved secret value as a string // - An error if the secret could not be resolved ResolveSecret(ctx context.Context, keyVaultReference url.URL) (string, error) }
SecretResolver is an interface to resolve secrets from Key Vault references. Implement this interface to provide custom secret resolution logic.
type Selector ¶
type Selector struct { // KeyFilter specifies which keys to retrieve from Azure App Configuration. // It can include wildcards, e.g. "app*" will match all keys starting with "app". KeyFilter string // LabelFilter specifies which labels to retrieve from Azure App Configuration. // Empty string or omitted value will use the default no-label filter. // Note: Wildcards are not supported in label filters. LabelFilter string }
Selector specifies what key-values to load from Azure App Configuration.
type WatchedSetting ¶
WatchedSetting specifies the key and label of a key-value setting to watch for changes