-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (39 loc) · 1010 Bytes
/
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
package main
import (
"net/http"
"os"
"github.com/Sirupsen/logrus"
"github.com/lnsp/webchat/chat"
"github.com/lnsp/webchat/config"
)
func main() {
var (
server *chat.Server
err error
)
if os.Getenv("DEBUG") != "" {
logrus.SetLevel(logrus.DebugLevel)
}
if cfg := os.Getenv("CONFIG_FILE"); cfg != "" {
server, err = config.Build(cfg)
if err != nil {
logrus.WithFields(logrus.Fields{
"config": cfg,
"error": err,
}).Fatal("Could not build server from configuration")
}
logrus.WithField("config", cfg).Info("Using configuration file")
} else {
server = chat.New()
logrus.Info("Using default configuration")
}
if err := server.Connect(os.Getenv("RABBITMQ_URL")); err != nil {
logrus.WithFields(logrus.Fields{
"url": os.Getenv("RABBITMQ_URL"),
"err": err,
}).Fatal("Could not connect to message broker")
}
http.Handle("/", http.FileServer(http.Dir("static")))
http.Handle("/chat/", server.Handler())
http.ListenAndServe(":"+os.Getenv("PORT"), nil)
}