beatlabs/harvester

Consul builder - Monitor from config

Closed this issue · 1 comments

Is your feature request related to a problem? Please describe

Provide a way to initialise Consul-monitored values based on the config instead of manually.

Describe the solution

Given a sample config

type Config struct {
	Foo sync.String `consul:"a/b/c/foo"`
	Bar sync.String `consul:"a/b/c/bar"`
}

Before

cfg := &Config{}
h, err := harvester.New(cfg).
		WithConsulMonitor(
			/* first params here */,
			consul.NewKeyItem("a/b/c/foo"), 
			consul.NewKeyItem("a/b/c/bar"),
		).
		Create()

Proposed solution

cfg := &Config{}
h, err := harvester.New(cfg).
		WithConsulMonitorFromConfig(
			/* first params here */,
			cfg
		).
		Create()

Where WithConsulMonitorFromConfig (or similar name) uses reflection to create the consul items automatically.

Benefits

Harvester would handle everything for us automatically. We could simply edit the Config object and we would know everything is monitored => no need to duplicate the key item in the config tag AND in the consul.NewKeyItem method or no need to put it in a const.

@aziule looks neat...