Skip to main content

Etcd Plugin

The Etcd module is both a config-center plugin and a service registry or discovery backend.

Runtime Facts

ItemValue
Go modulegithub.com/go-lynx/lynx-etcd
Config prefixlynx.etcd
Runtime plugin nameetcd.config.center
Public APIsGetClient(), GetEtcdConfig(), GetNamespace(), GetConfigSources(), GetConfigValue(prefix, key)

What The Implementation Provides

The code supports:

  • config loading from an Etcd prefix
  • multiple config prefixes with merge strategy
  • optional local cache
  • retry, graceful shutdown, metrics, and health checks
  • optional service registration
  • optional service discovery and watchers

So this plugin is broader than "read a few keys from Etcd".

Configuration

lynx:
etcd:
endpoints:
- "127.0.0.1:2379"
namespace: "lynx/config"
enable_register: true
enable_discovery: true
registry_namespace: "lynx/services"
ttl: 30s
service_config:
prefix: "lynx/config"
additional_prefixes:
- "lynx/config/shared"
merge_strategy: "override"

What The Official Template Uses

The official template does not enable Etcd by default. The current scaffold uses Polaris as its control-plane example instead.

That is important because Etcd serves two very different roles in Lynx:

  • config-center and service-registry infrastructure
  • runtime dependency for higher-level features such as Etcd Lock

So this page should be read as "how to bring Etcd into the runtime when your environment needs it", not as something the base template already wires.

How To Consume It

plugin := lynx.Lynx().GetPluginManager().GetPlugin("etcd.config.center")
etcdPlugin := plugin.(*etcd.PlugEtcd)

client := etcdPlugin.GetClient()
sources, err := etcdPlugin.GetConfigSources()
value, err := etcdPlugin.GetConfigValue("lynx/config", "my.key")

For service registration and discovery, the module also exposes registrar and discovery implementations such as NewEtcdRegistrar and NewEtcdDiscovery.

Practical Notes

  • namespace and service_config.prefix affect configuration lookup, while registry_namespace affects service instance paths.
  • Enabling register or discovery changes this plugin from pure config-center usage into control-plane infrastructure.
  • Etcd Lock depends on this plugin's runtime resource.