# README
Go Config Client
This is the config client for Go projects.
- File-Based Client - Fully Implemented
- ETCD Client - TBD
- AWS App Config Client - Fully Implemented
Project Versioning
Go Config Client uses semantic versioning. API should not change between patch and minor releases. New minor versions may add additional features to the API.
Installation
To install Go Config Client
package, you need to install Go and set your Go workspace first.
- The first need Go installed (version 1.13+ is required), then you can use the below Go command to install Go Config Client.
go get github.com/sinhashubham95/go-config-client
- Because this is a private repository, you will need to mark this in the Go env variables.
go env -w GOPRIVATE=github.com/sinhashubham95/*
- Also, follow this to generate a personal access token and add the following line to your $HOME/.netrc file.
machine github.com login ${USERNAME} password ${PERSONAL_ACCESS_TOKEN}
- Import it in your code:
import configs "github.com/sinhashubham95/go-config-client"
Usage
New Client
import configs "github.com/sinhashubham95/go-config-client"
fileBasedClient, _ := configs.New(configs.Options{
Provider: configs.FileBased,
Params: map[string]interface{}{
"configsDirectory": ".",
"configNames": []string{"configs"},
"configType": "json",
},
})
awsAppConfigClient, _ := configs.New(configs.Options{
Provider: configs.AWSAppConfig,
Params: map[string]interface{}{
"id": "example-go-config-client",
"region": os.Getenv("region"),
"accessKeyId": os.Getenv("accessKeyId"),
"secretKey": os.Getenv("secretKey"),
"app": "sample",
"env": "sample",
"configType": "json",
"configNames": []string{"sample"},
}
})
Configuring Secrets Manager
- Add additional param secretNames as shown below
- App Config and SecretsManager will use same access and secret keys hence makes sure necessary access is available
- Secrets values are fetched on startup time and cached by library. Restart needed if changing secrets.
- Secret data in case of AWS should contain JSON data only.
import configs "github.com/sinhashubham95/go-config-client"
fileBasedClient, _ := configs.New(configs.Options{
Provider: configs.FileBased,
Params: map[string]interface{}{
"configsDirectory": ".",
"configNames": []string{"configs"},
"configType": "json",
"secretsDirectory": ".",
"secretNames": []string{"secrets"},
"secretType": "json",
},
})
awsAppConfigClient, _ := configs.New(configs.Options{
Provider: configs.AWSAppConfig,
Params: map[string]interface{}{
"id": "example-go-config-client",
"region": os.Getenv("region"),
"accessKeyId": os.Getenv("accessKeyId"),
"secretKey": os.Getenv("secretKey"),
"app": "sample",
"env": "sample",
"configType": "json",
"configNames": []string{"sample"},
"secretNames": []string{"SecretName"},
}
})
Getting Secrets Value
- New methods have been exposed to fetch secrets GetSecret, GetIntSecret, GetFloatSecret and GetStringSecret.
- Secrets values are fetched on startup time and cached by library. Restart needed if changing secrets.
Getting Configs
There are 2 types of methods available.
- Plain methods which take the config name and the key.
- Methods with default values which take the config name, key and the default value. The default value will be used in case the value is not found in the config mentioned corresponding to the key asked for.
Note
For File Based Config Client, the config name is the name of the file from where the configurations have to be referenced, and the key is the location of the config being fetched from that configuration file.
For AWS App Config Client, the config name is the name of the configuration profile deployed, and the key is the location of the config being fetched from that configuration profile.
# Packages
No description provided by the author
# Functions
New is used to initialise and get the instance of a config client.
No description provided by the author
# Constants
credential modes.
credential modes.
These are the providers available.
These are the providers available.
# Variables
generic errors.
generic errors.
ErrProviderNotSupported is the error used when the provider is not supported.
generic errors.
# Structs
Options is the set of configurable parameters required for initialisation of the config client.
# Interfaces
Client is the contract that can be used and will be followed by every implementation of the config client.
# Type aliases
ChangeListener is called whenever any change happens in the config.