π Config References
One of the biggest superpowers of our config management system is References! π¦ΈββοΈ
Instead of copy-pasting the same settings everywhere, you can pass a reference to an existing config instance. This keeps your configurations incredibly organized, DRY (Don't Repeat Yourself), and highly reusable.
βοΈ How It Worksβ
When you inject a reference into your config, the configuration manager detects it, parses it, and saves it to be resolved later.
When your service finally requests its configuration, the manager performs a dynamic lookup and completely replaces your reference with the actual, live configuration! πͺ
The manager needs two things to understand your reference:
- The name of the config you want.
- The version of that config (you can safely use
"latest"to always grab the newest version).
The manager takes the referenced config and smoothly merges it into your current configuration right at the exact hierarchy level where you placed the reference.
ποΈ Reference Structureβ
To wire up a reference, you just drop in an object formatted exactly like this:
{
"$ref": {
"configName": "requested-config",
"version": "latest"
}
}
Working in the config-ui editor? Just press Ctrl + Space to instantly drop in a handy reference snippet! β¨οΈβ‘
π‘ Example Usageβ
Imagine you are setting up a database connection for your shiny new app.
You know there is already a solid base configuration called db-partial, which has everything you need except the actual database name.
{
"ssl": {
"enabled": false
},
"host": "avi"
}
Instead of copying it, you create a new configuration that simply references db-partial and tacks on your specific database name:
{
"$ref": {
"configName": "db-partial",
"version": "latest"
},
"database": "my-db"
}
The Final Result: When your app fetches the config, it magically receives the fully resolved object! π
{
"ssl": {
"enabled": false
},
"host": "avi",
"database": "my-db"
}