#Best practices providing db credential
10 messages · Page 1 of 1 (latest)
use environment variables
(really complex example how I streamlined most of my configuration needs: https://github.com/jxsl13/twstatus-bot)
First of all thank you for the reply, I'm a noobie in go so I might be wrong, I checked out your repo and I saw that you are hardcoding some of the db config variables like user, port,db name... (main.go). That's exactly what I want to skip, so I guess that as you pointed out I should stick to en variables
I'm not hardcoding them, I am providing defaults
that can be overwritten by cli flags, environment variables or by a config file passed either by a special environment variable or passed by the -c or --config cli flag
most of the time you will use the same database port
but might want to change the database host/ip
(the complex stuff happens in config/koanf.go)
sane defaults allow you to reduce the size of yout configuration.
In my case, a user would only need to care about half of my configuration options because the rest of them has a sane default value: