DEV Community

Discussion on: Clean Configuration Management in Golang

Collapse
 
billa profile image
William Aylesworth

what about a function to write out the configuration to a file.
Like SaveConfig(path string, cfg interface{}) error

Collapse
 
ilyakaznacheev profile image
Ilya Kaznacheev • Edited

Honestly, I didn't think anybody would want it. In which cases could it be used?

Collapse
 
billa profile image
William Aylesworth

Not sure if there is the correct use case for your package. The go program I am building needs a config file for API logins and passwords. The config file will have human readable values but I need to save an encrypted value for a password. I use Setter to unencrypt the value. But I am building a config file editor to allow editing the text password and then encrypt it in the config file.

Thread Thread
 
ilyakaznacheev profile image
Ilya Kaznacheev

I think you can just use gopkg.in/yaml.v2 to encrypt any structure to YAML and print it to the file. So you don't need any special logic here, because your app prepares some data (which is out of the scope of how to push it to the file), and then you just need to save it.

You also can use default json or toml encoders if you want. No real need to build something extra.