-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (46 loc) · 1.59 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
package main
import (
"certcheckerServer/handlers"
"certcheckerServer/hub"
"certcheckerServer/libhelper"
"certcheckerServer/models"
"github.com/desertbit/glue"
"github.com/gorilla/mux"
"net/http"
)
func main() {
connectionString := libhelper.GetEnvOrDefault("CONNECTIONSTRING", "mongodb://localhost")
databaseName := libhelper.GetEnvOrDefault("DATABASENAME", "certchecker")
redisUrl := libhelper.GetEnvOrDefault("REDISURL", "redis://localhost")
db, err := models.ConnectToDatabase(connectionString, databaseName)
if err != nil {
panic(err)
}
env := &handlers.Env{
Db: db,
}
defer env.Db.Close()
glueServer := glue.NewServer(glue.Options{
HTTPSocketType: glue.HTTPSocketTypeNone,
HTTPHandleURL: "/ws/",
CheckOrigin: func(r *http.Request) bool { return true },
})
defer glueServer.Release()
err = hub.InitHub(redisUrl)
if err != nil {
panic(err)
}
glueServer.OnNewSocket(hub.HandleSocket)
r := mux.NewRouter()
r.HandleFunc("/certificates", env.GetCerticates).Methods("GET")
r.HandleFunc("/certificate/{id}", env.GetCertificate).Methods("GET")
r.HandleFunc("/certificates", env.PostCertificate).Methods("POST")
r.HandleFunc("/servers", env.GetServers).Methods("GET")
r.HandleFunc("/server/{id}", env.GetServer).Methods("GET")
r.HandleFunc("/server/certificates/{id}", env.GetServerCertificates).Methods("GET")
r.PathPrefix("/").Handler(http.FileServer(http.Dir("./public/")))
http.Handle("/", r)
http.Handle("/ws/", glueServer)
http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("./public/"))))
http.ListenAndServe(":3000", nil)
}