-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
75 lines (56 loc) · 1.41 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"github.com/masom/doorbot/doorbot"
"github.com/masom/doorbot/doorbot/api"
"github.com/masom/envconfig"
"github.com/go-martini/martini"
log "github.com/Sirupsen/logrus"
_ "github.com/stretchr/testify/mock"
"math/rand"
"os"
"time"
)
func Configure() *doorbot.DoorbotConfig {
c := &doorbot.DoorbotConfig{}
c.Database = doorbot.DatabaseConfig{}
c.Server = doorbot.ServerConfig{}
if os.Getenv("HEROKU") != "" {
log.Info("Using HEROKU config")
hc := &doorbot.HerokuConfig{}
err := envconfig.Process("", hc)
if err != nil {
log.Panic(err)
}
log.Println(hc)
c.Database.URL = hc.DatabaseUrl
c.Server.Port = hc.Port
c.UserAccountsDomain = hc.UserAccountsDomain
c.ParseDomains(hc.Domains)
} else {
log.Info("Using ENV config.")
ec := &doorbot.EnvConfig{}
err := envconfig.Process("doorbot", ec)
if err != nil {
log.Panic(err)
}
log.Println(ec)
c.ParseDomains(ec.Domains)
c.UserAccountsDomain = ec.UserAccountsDomain
c.Database.URL = ec.DatabaseUrl
c.Database.Trace = ec.DatabaseTrace
c.Server.Port = ec.ServerPort
}
log.Info(fmt.Sprintf("Database URL: `%s`", c.Database.URL))
return c
}
func setupLogging() {
log.SetLevel(log.DebugLevel)
}
func main() {
rand.Seed(time.Now().UTC().UnixNano())
config := Configure()
m := api.NewServer(config)
m.Use(martini.Static("public", martini.StaticOptions{IndexFile: "public/index.html"}))
m.Run()
}