-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
40 lines (32 loc) · 1.02 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
package main
import (
"log"
"net/http"
"com.mixin.morphine/core"
"com.mixin.morphine/routes"
"github.com/go-redis/redis/v9"
"github.com/gorilla/mux"
"github.com/joho/godotenv"
)
func main() {
if err := godotenv.Load(); err != nil {
log.Fatal("SYSTEM::ENVIRONMENT: failed to load environment variables from godotenv")
}
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
})
hub := core.Generate_HubService()
router := mux.NewRouter()
go hub.Run()
router.HandleFunc("/analytics", routes.ServerAnalytics()).Methods("GET")
router.HandleFunc("/webhook", routes.Webhook(hub)).Methods("POST")
router.HandleFunc("/connections", routes.ReadConnections(hub, rdb)).Methods("GET")
router.HandleFunc("/connect", routes.CreateWebsocket(hub, rdb))
log.Printf("RUNNING::SERVER: http://localhost:4001/")
err := http.ListenAndServe(":4001", router)
if err != nil {
log.Fatal("RUNNING::SERVER: ", err)
}
}