diff --git a/README.md b/README.md index 45fe13f5..a45b1364 100644 --- a/README.md +++ b/README.md @@ -14,20 +14,20 @@ data retention on a more reliable database. #### MySQL -When using MySQL, you will be required to specify a `MYSQL_CONNECTION` environment variable with the connection string +When using MySQL, you will be required to specify a `DB_CONN_STR` environment variable with the connection string to your MySQL database. For example: ```text -MYSQL_CONNECTION="root:Password01@tcp(localhost:3306)/puppet-summary?timeout=90s&multiStatements=true&parseTime=true" +DB_CONN_STR="root:Password01@tcp(localhost:3306)/puppet-summary?timeout=90s&multiStatements=true&parseTime=true" ``` #### MongoDB -When using MongoDB, you will be required to specify a `MONGO_URI` environment variable with the connection URI to your +When using MongoDB, you will be required to specify a `DB_CONN_STR` environment variable with the connection URI to your MongoDB database. For example: ```text -MONGO_URI="mongodb+srv://user:password@host/?retryWrites=true" +DB_CONN_STR="mongodb+srv://user:password@host/?retryWrites=true" ``` #### Google Cloud Storage diff --git a/pkg/dataaccess/db.go b/pkg/dataaccess/db.go index 2d6da5cd..f1bb8d61 100644 --- a/pkg/dataaccess/db.go +++ b/pkg/dataaccess/db.go @@ -8,6 +8,8 @@ import ( "github.com/Jacobbrewer1/puppet-summary/pkg/entities" ) +const envDbConnStr = "DB_CONN_STR" + var DB Database type Database interface { diff --git a/pkg/dataaccess/db_mongo.go b/pkg/dataaccess/db_mongo.go index 8a06c278..a89f8f77 100644 --- a/pkg/dataaccess/db_mongo.go +++ b/pkg/dataaccess/db_mongo.go @@ -17,12 +17,10 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -const EnvMongoURI = `MONGO_URI` - const mongoDatabase = "puppet-summary" func connectMongoDB(ctx context.Context) { - connectionString := os.Getenv(EnvMongoURI) + connectionString := os.Getenv(envDbConnStr) if connectionString != "" { slog.Debug("Found MongoDB URI in environment") } else { diff --git a/pkg/dataaccess/db_mysql.go b/pkg/dataaccess/db_mysql.go index a33fa382..384cabca 100644 --- a/pkg/dataaccess/db_mysql.go +++ b/pkg/dataaccess/db_mysql.go @@ -15,10 +15,8 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -const EnvMySQLConnection = `MYSQL_CONNECTION` - func connectMysql() { - connectionString := os.Getenv(EnvMySQLConnection) + connectionString := os.Getenv(envDbConnStr) if connectionString != "" { slog.Debug("Found MySQL URI in environment") } else {