#Best practices providing db credential

10 messages · Page 1 of 1 (latest)

bitter veldt
#

I wanna know about best practices providing db credentials to a go project. I don't wanna hardcode the database URI. I'm using goose package in order to run migrations just in case there is a tool that combines with goose in order to define the db string URI (sqlboiler, maybe)

Thank you in advance

proven furnace
#

use environment variables

bitter veldt
proven furnace
#

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: