Skip to content

Commit 7dc8322

Browse files
committed
Add individual env for DB
1 parent 2f12439 commit 7dc8322

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

db/database.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,28 @@ func (d *Database) LookupDatabasePath() string {
9393
var ok bool
9494

9595
if path, ok = os.LookupEnv("DATABASE_PATH"); !ok {
96-
log.Fatal("DATABASE_PATH cannot be empty. use the following format: postgresql://user:password@server:port/dbname")
97-
return ""
96+
username, ok := os.LookupEnv("DATABASE_USERNAME")
97+
if !ok {
98+
log.Println("DATABASE_USERNAME unset")
99+
}
100+
password, ok := os.LookupEnv("DATABASE_PASSWORD")
101+
if !ok {
102+
log.Println("DATABASE_PASSWORD unset")
103+
}
104+
host, ok := os.LookupEnv("DATABASE_HOST")
105+
if !ok {
106+
log.Println("DATABASE_HOST unset")
107+
}
108+
dbname, ok := os.LookupEnv("DATABASE_NAME")
109+
if !ok {
110+
log.Println("DATABASE_NAME unset")
111+
}
112+
113+
path = fmt.Sprintf("postgresql://%s:%s@%s/%s", username, password, host, dbname)
114+
115+
return path
98116
} else {
117+
99118
return path
100119
}
101120
}

0 commit comments

Comments
 (0)