knadh / koanf

Simple, extremely lightweight, extensible, configuration management library for Go. Support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.
MIT License
2.79k stars 153 forks source link

nats read write #310

Closed gedw99 closed 2 months ago

gedw99 commented 2 months ago

Because nats is reactive a KV change will ripple through to all other servers that also use koanf.

I was wondering if the other server will get the nats updates without a restart ? Or do I need to reload the other apps using koanf ? Would be very useful for my use cases if all apps config updating in real time.

Also there is no example of nats usage in the repo :)

knadh commented 2 months ago

https://github.com/knadh/koanf/blob/master/providers/nats/nats.go

Hi @gedw99. From looking at the code, the provider doesn't auto-update. It reads values from the JetStream keystore once on initialization like any other provider. There's an optional Watch() callback (just like the file provider) which can be used for getting a callback if there's a live change. There, you can decide whether to ignore or reload config or restart the application etc.

If you end up using the provider, please do consider sending a PR with an example implementation!

gedw99 commented 2 months ago

Thanks @knadh

ah interesting that there is “watch”. It’s like an FS watch .

Maybe I can add a nats watch too . So that if values change in nats kv, it updates in real time without being dependent on the file system ?

yes I will def add an example … :)

knadh commented 2 months ago

Maybe I can add a nats watch too . So that if values change in nats kv, it updates in real time without being dependent on the file system ?

This already exists in the provider. You just have to use Watch() which is triggered when there's a KV change.

gedw99 commented 1 month ago

Maybe I can add a nats watch too . So that if values change in nats kv, it updates in real time without being dependent on the file system ?

This already exists in the provider. You just have to use Watch() which is triggered when there's a KV change.

ah User training :) thanks @knadh for your patience ...

This is really awesome with the watcher ...

https://github.com/cirello-io/runner is a runner that can do formations, like Docker compose.

So we can manage dockers across global deployments with Configs "linked" to other Configs.

NATS can models any config aspects that are parametric, where one system is dependent on another systems config value. Like a google spreadsheet when when you change one value it causes the values in other cells to change...

SO will get koanf using NATS with a Google Sheet like GUI of the normalised and denormalised configs.

Might write a koanf fmt, to spot same values across configs, to spot what is parametric, and automatically re-generate the config into one where the isolated parametric value(s) is mapped to NATS.

The GUI is this: https://github.com/gedw99/goPocJsonSchemaForm that can real time present the config for Read and Write CQRS setups, like what this really is.