/
config.go
62 lines (56 loc) · 1.74 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"github.com/bmizerany/pq" // Postgres Database Driver
"os"
)
// Get the Postgres Database Url.
func getDatabaseUrl() string {
var database_url = os.Getenv("DATABASE_URL")
// Set a default database url if there is nothing in the environemnt
if database_url == "" {
// Postgres.app uses this variable to set-up postgres.
user := os.Getenv("USER")
// Inject the username into the connection string
database_url = "postgres://" + user + "@localhost/up?sslmode=disable"
// Let the user know they are using a default
fmt.Println("INFO: No DATABASE_URL env var detected, defaulting to " + database_url)
}
conn_str, err := pq.ParseURL(database_url)
if err != nil {
panic("Unable to Parse DB URL connection string: " + database_url)
}
return conn_str
}
// Get the Port from the environment so we can run on Heroku
func getPort() string {
var port = os.Getenv("PORT")
// Set a default port if there is nothing in the environment
if port == "" {
port = "4747"
fmt.Println("INFO: No PORT environment variable detected, defaulting to " + port)
}
return ":" + port
}
// Get the Port from the environment so we can run on Heroku
func getDebug() bool {
var debugenv = os.Getenv("DEBUG")
debug := false
// Set a default port if there is nothing in the environment
if debugenv == "true" {
debug = true
}
return debug
}
func getEmailConfig() MailAuth {
auth := MailAuth{Sender: os.Getenv("EMAIL_SENDER"), Password: os.Getenv("EMAIL_PASSWORD"), Host: os.Getenv("EMAIL_HOST")}
return auth
}
// Get the secret key for interacting with the application
func getSecret() string {
var secret = os.Getenv("SECRET")
if secret == "" {
panic("You must set a SECRET in your environment.\n\n $ export SECRET=foo")
}
return secret
}