File tree Expand file tree Collapse file tree
05-example-web-application Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package main
22
33import (
4+ "io/ioutil"
45 "log"
56 "os"
67 "time"
@@ -11,7 +12,16 @@ import (
1112)
1213
1314func init () {
14- errDB := database .InitDB (os .Getenv ("DATABASE_URL" ))
15+ databaseUrl := os .Getenv ("DATABASE_URL" )
16+ if databaseUrl == "" {
17+ content , err := ioutil .ReadFile (os .Getenv ("DATABASE_URL_FILE" ))
18+ if err != nil {
19+ log .Fatal (err )
20+ }
21+ databaseUrl = string (content )
22+ }
23+
24+ errDB := database .InitDB (databaseUrl )
1525 if errDB != nil {
1626 log .Fatalf ("⛔ Unable to connect to database: %v\n " , errDB )
1727 } else {
Original file line number Diff line number Diff line change 1+ const fs = require ( 'fs' ) ;
2+
13const { Pool } = require ( 'pg' ) ;
24
5+ databaseUrl =
6+ process . env . DATABASE_URL ||
7+ fs . readFileSync ( process . env . DATABASE_URL_FILE , 'utf8' ) ;
8+
39const pool = new Pool ( {
4- connectionString : process . env . DATABASE_URL ,
10+ connectionString : databaseUrl ,
511} ) ;
612
713// the pool will emit an error on behalf of any idle clients
You can’t perform that action at this time.
0 commit comments