Package dburl allows you to configure your database configuration based on DATABASE_URL environment variable.
The package provides Config(string) function to generate configuration based on environment variable passed as an argument. Function returns a database config structure, populated with all the data specified in your environment variable. Package helps to create config for docker based applications, which depends on external database.
If you'd rather not use an environment variable, you can pass a URL in directly instead to Parse(string) method.
Currently supports the following databases: PostgreSQL, MSSQL and SQLite. (I plan to expand this list in the future)
Installation is simple
$ go get github.com/mateusz-szczesny/dburl
Configure your database with default environment variable ("DATABASE_URL")
import (
...
"github.com/mateusz-szczesny/dburl"
)
db, err := dburl.Config(dburl.DefaultEnv)
Provide a custom environment variable name
db, err := dburl.Config("MY_CUSTOM_VARIABLE_NAME")
Engine | URL |
---|---|
PostgreSQL | postgres://USER:PASSWORD@HOST:PORT/NAME |
MSSQL | mssql://USER:PASSWORD@HOST:PORT/NAME |
SQLite | sqlite3:///path/to/some/database.db |