Skip to main content

πŸ”— 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:

  1. The name of the config you want.
  2. 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"
}
}
Pro Tip!

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.

db-partial
{
"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:

db-full
{
"$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"
}