forked from snickers/snickers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (49 loc) · 1.07 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
package main
import (
"os"
"code.cloudfoundry.org/lager"
"github.com/flavioribeiro/gonfig"
"github.com/snickers/snickers/db"
"github.com/snickers/snickers/server"
)
func main() {
currentDir, err := os.Getwd()
if err != nil {
panic(err)
}
config, err := gonfig.FromJsonFile(currentDir + "/config.json")
if err != nil {
panic(err)
}
log, err := setupLogger(config)
if err != nil {
panic(err)
}
db, err := db.GetDatabase(config)
if err != nil {
panic(err)
}
port, err := config.GetString("PORT", "8000")
if err != nil {
panic(err)
}
snickersServer := server.New(log, config, "tcp", ":"+port, db)
snickersServer.Start(true)
}
func setupLogger(config gonfig.Gonfig) (lager.Logger, error) {
log := lager.NewLogger("snickers")
logfile, err := config.GetString("LOGFILE", "")
if err != nil {
return nil, err
}
if logfile != "" {
f, err := os.Create(logfile)
if err != nil {
return nil, err
}
log.RegisterSink(lager.NewWriterSink(f, lager.DEBUG))
} else {
log.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
}
return log, nil
}