diff --git a/azureappconfiguration/README.md b/azureappconfiguration/README.md new file mode 100644 index 0000000..41f33e3 --- /dev/null +++ b/azureappconfiguration/README.md @@ -0,0 +1,44 @@ +# Azure App Configuration - Go Provider + +[![PkgGoDev](https://pkg.go.dev/badge/github.com/Azure/AppConfiguration-GoProvider/azureappconfiguration)](https://pkg.go.dev/github.com/Azure/AppConfiguration-GoProvider/azureappconfiguration) + +## Overview + +[Azure App Configuration](https://docs.microsoft.com/azure/azure-app-configuration/overview) provides centralized configuration storage and management, allowing users to update their configurations without the need to rebuild and redeploy their applications. The App Configuration provider for Go is built on top of the [Azure Go SDK](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig) and is designed to simplify data consumption in App Configuration with rich features. Users can consume App Configuration key-values as strongly-typed structs with data binding or load them into popular third-party configuration libraries, minimizing code changes. The Go provider offers features such as configuration composition from multiple labels, key prefix trimming, automatic resolution of Key Vault references, feature flags, failover with geo-replication for enhanced reliability, and many more. + +## Installation + +```bash +go get github.com/Azure/AppConfiguration-GoProvider/azureappconfiguration +``` + +## Examples + +- [Console Application](../example/console-example/): Load settings from Azure App Configuration and use in a console application. +- [Web Application](../example/gin-example/): Load settings from Azure App Configuration and use in a Gin web application. + +## Data Collection + +The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry by setting the environment variable `AZURE_APP_CONFIGURATION_TRACING_DISABLED` to `TRUE`. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft’s privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices. + +## Contributing + +This project welcomes contributions and suggestions. Most contributions require you to agree to a +Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us +the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. + +When you submit a pull request, a CLA bot will automatically determine whether you need to provide +a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions +provided by the bot. You will only need to do this once across all repos using our CLA. + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or +contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. + +## Trademarks + +This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft +trademarks or logos is subject to and must follow +[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). +Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. +Any use of third-party trademarks or logos are subject to those third-party's policies. diff --git a/azureappconfiguration/azureappconfiguration.go b/azureappconfiguration/azureappconfiguration.go index 84f3ed0..a6228ef 100644 --- a/azureappconfiguration/azureappconfiguration.go +++ b/azureappconfiguration/azureappconfiguration.go @@ -58,13 +58,13 @@ type AzureAppConfiguration struct { // 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 +// - 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 +// - 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 Load(ctx context.Context, authentication AuthenticationOptions, options *Options) (*AzureAppConfiguration, error) { if err := verifyAuthenticationOptions(authentication); err != nil { return nil, err @@ -123,11 +123,11 @@ func Load(ctx context.Context, authentication AuthenticationOptions, options *Op // 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 +// - 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 +// - An error if unmarshalling fails due to type conversion issues or invalid configuration func (azappcfg *AzureAppConfiguration) Unmarshal(v any, options *ConstructionOptions) error { if options == nil || options.Separator == "" { options = &ConstructionOptions{ @@ -162,11 +162,11 @@ func (azappcfg *AzureAppConfiguration) Unmarshal(v any, options *ConstructionOpt // 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 +// - 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 +// - A byte array containing the JSON representation of the configuration +// - An error if JSON marshalling fails or if an invalid separator is specified func (azappcfg *AzureAppConfiguration) GetBytes(options *ConstructionOptions) ([]byte, error) { if options == nil || options.Separator == "" { options = &ConstructionOptions{ @@ -186,17 +186,17 @@ func (azappcfg *AzureAppConfiguration) GetBytes(options *ConstructionOptions) ([ // 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 +// - 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. +// - ctx: The context for the operation. // // Returns: -// - An error if refresh is not configured, or if the refresh operation fails +// - An error if refresh is not configured, or if the refresh operation fails func (azappcfg *AzureAppConfiguration) Refresh(ctx context.Context) error { if azappcfg.kvRefreshTimer == nil && azappcfg.secretRefreshTimer == nil { return fmt.Errorf("refresh is not enabled for either key values or Key Vault secrets") @@ -246,7 +246,7 @@ func (azappcfg *AzureAppConfiguration) Refresh(ctx context.Context) error { // in the thread that initiated the refresh. // // Parameters: -// - callback: A function with no parameters that will be called after a successful refresh +// - callback: A function with no parameters that will be called after a successful refresh func (azappcfg *AzureAppConfiguration) OnRefreshSuccess(callback func()) { azappcfg.onRefreshSuccess = append(azappcfg.onRefreshSuccess, callback) } diff --git a/azureappconfiguration/options.go b/azureappconfiguration/options.go index 9716786..595e46d 100644 --- a/azureappconfiguration/options.go +++ b/azureappconfiguration/options.go @@ -85,12 +85,12 @@ 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}" + // - 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 + // - 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) }