-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (42 loc) · 1.19 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
package main
import (
"fmt"
// Standard lib imports
"flag" // Used for command line flag parsing
// Handle network
"net/http"
// Server imports
"github.com/HEEV/WebServer/chat"
// Logging imports
debugFname "github.com/onrik/logrus/filename"
log "github.com/sirupsen/logrus"
)
var port int
func init() {
var debug, verbose bool
flag.BoolVar(&debug, "debug", false, "Run the API in debug mode")
flag.BoolVar(&debug, "d", false, "Run the API in debug mode")
flag.BoolVar(&verbose, "verbose", false, "Run the API in verbose mode")
flag.BoolVar(&verbose, "v", false, "Run the API in verbose mode")
flag.IntVar(&port, "port", 8000, "Specify which port the API will run on")
flag.Parse()
log.Info("Initializing server...")
if debug {
log.Warn("Starting server in debug mode!")
} else if verbose {
log.Warn("Starting server in verbose mode!")
}
if debug || verbose {
log.SetLevel(log.DebugLevel)
log.AddHook(debugFname.NewHook())
}
}
func main() {
// Initialize websocket hub
hub := chat.NewHub()
go hub.Run()
// Initialize HTTP server instance
initializeRoutes(hub)
log.Warnf("Server starting on :%d", port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
}