Skip to content

Commit b54d7e4

Browse files
committed
Allows database information to come from environment
1 parent 2a4b8d0 commit b54d7e4

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

gobb/gobb.sample.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ username=db_username
2121
password=db_password
2222
database=db_name
2323
hostname=localhost
24+
port=5432
25+
26+
;; These options are used for docker port redirection.
27+
;; env_hostname=POSTGRES_PORT_5432_TCP_PORT
28+
;; env_port=POSTGRES_PORT_5432_TCP_ADDR
2429

2530
;; If you have a Google Analytics account, put your information
2631
;; in this section (optional)

models/connection.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/coopernurse/gorp"
77
_ "github.com/lib/pq"
88
"github.com/stevenleeg/gobb/config"
9+
"os"
910
)
1011

1112
var db_map *gorp.DbMap
@@ -21,6 +22,17 @@ func GetDbSession() *gorp.DbMap {
2122
db_hostname, _ := config.Config.GetString("database", "hostname")
2223
db_port, _ := config.Config.GetString("database", "port")
2324

25+
db_env_hostname, _ := config.Config.GetString("database", "env_hostname")
26+
db_env_port, _ := config.Config.GetString("database", "env_port")
27+
28+
// Allow database information to come from environment variables
29+
if db_env_hostname != "" {
30+
db_hostname = os.Getenv(db_env_hostname)
31+
}
32+
if db_env_port != "" {
33+
db_port = os.Getenv(db_env_port)
34+
}
35+
2436
if db_port == "" {
2537
db_port = "5432"
2638
}

0 commit comments

Comments
 (0)