-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (50 loc) · 1.37 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
// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"flag"
"fmt"
"net/http"
"os"
"stack-web-app/db"
"stack-web-app/wshandler"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
)
func main() {
// Get any necessary environment variables
_, debug := os.LookupEnv("DEBUG")
// Set logger settings
log.SetOutput(os.Stdout)
log.SetFormatter(&log.JSONFormatter{})
if debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
// Set up gorilla mux router handling
flag.Parse()
db.Start()
go wshandler.PruneEmptyMeetings()
router := mux.NewRouter()
router.HandleFunc("/", wshandler.GetWS).Methods("GET")
router.HandleFunc("/", wshandler.PostWS).Methods("POST")
// Set up request logging
loggedRouter := handlers.LoggingHandler(os.Stdout, router)
// Setting some required pieces for DigitalOcean app platform support
port := os.Getenv("PORT")
if port == "" {
port = "80"
}
log.WithFields(log.Fields{
"port": port,
}).Info(fmt.Sprintf("==> Server listening on port %s 🚀", port))
err := http.ListenAndServe(fmt.Sprintf(":%s", port), loggedRouter)
if err != nil {
log.WithFields(log.Fields{
"error": err.Error(),
}).Fatal("Fatal error with HTTP server")
}
}