Programming patterns: storing runtime configuration

123 views
Skip to first unread message

cpu...@gmail.com

unread,
Aug 14, 2024, 3:37:09 PM8/14/24
to golang-nuts
Hope the question is not too OT for this group, if yes please just ignore it and forgive me.

We're in the progress of migrating a somewhat-complex application (https://github.com/evcc-io/evcc) from static, yaml-based configuration to fully UI-controllable dynamic config. A running application manages some 5-20 configurable objects. Using yaml, config was just public properties of structs manages by yaml.Unmarshal. We could continue doing so and maybe use json.(Un)Marshal to put the identical structs into a database table, but it feels odd to have public properties in objects/structs just for the purpose of storing an manipulating their configuration.

What are good patterns for managing runtime config and is there any project you can recommend to look at that does this particularly well or elegant?

Thanks,
Andi

Jason E. Aten

unread,
Aug 16, 2024, 3:27:01 AM8/16/24
to golang-nuts
I don't think its off topic.  But: I don't really get a feel for the problem/challenge that you are facing, so its a little hard to try and help.  Maybe unpacking the term "runtime config" would help. How is "runtime config" different from regular configuration files or structs?  

I do usually have a separate "config" struct for each "service" struct. And the config structs entire point is to have public members that are serialized and deserialized; and filled in from command line parameter flags.

If configuration just needs to be "more dynamic", and just to suggest something to let you react to, I wrote a scripting language to configure trees of structs and their parameters at runtime.  But, again, this is just a stab in the dark since the challenge you are facing is a little vague to me. https://github.com/glycerine/zygomys is that scripting language. The full generality of a programming language isn't usually needed for configuration, but it is, on occasion, very convenient.

If you use command line flags and want to combine several libraries that use command line flags for configuration into one program, then I use the pattern described here to good effect: https://github.com/glycerine/configs-in-golang

Reply all
Reply to author
Forward
0 new messages