-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (57 loc) · 1.09 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"time"
"drawing/api/ws"
"drawing/models"
"drawing/routes"
"drawing/services"
"drawing/utils"
"github.com/urfave/negroni"
)
func determineListenAddress() (string, error) {
port := os.Getenv("PORT")
if port == "" {
return ":3000", fmt.Errorf("$PORT not set")
}
return ":" + port, nil
}
func connectDatabase() {
db, err := models.Connect()
if err != nil {
log.Fatalf("Connection error: %s", err.Error())
}
models.SetDatabase(db)
}
func awsSession() {
sess, err := services.AWSSession()
if err != nil {
log.Fatalf("Connection error: %s", err.Error())
}
services.AWS(sess)
}
func websoketHub() {
hub := ws.H
go hub.Run()
}
func main() {
connectDatabase()
awsSession()
websoketHub()
addr, _ := determineListenAddress()
routes := routes.NewRoutes()
n := negroni.Classic()
n.Use(utils.AllowCors())
n.UseHandler(routes)
s := &http.Server{
Addr: addr,
Handler: n,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
log.Fatal(s.ListenAndServe())
}