-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
93 lines (67 loc) · 2.93 KB
/
main.go
File metadata and controls
93 lines (67 loc) · 2.93 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"log"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/gorilla/websocket"
"github.com/joho/godotenv"
"github.com/open-hack/back-end/handler"
"github.com/open-hack/back-end/model"
"github.com/open-hack/back-end/service"
"gopkg.in/olivere/elastic.v6"
)
func main() {
routes := mux.NewRouter()
db := model.WeeHackDB{}
//Inicialização do repositorio
db.MustInit()
if err := godotenv.Load(); err != nil {
log.Println("File .env not found, reading configuration from ENV")
}
elasticClient, err := elastic.NewClient(elastic.SetURL(model.ElasticSearch()), elastic.SetSniff(false))
if err != nil {
log.Fatal("Error Creating Elastic Client: ", err)
}
log.Printf("Elastic Search Client Created")
elasticService := &service.ElasticService{
ElasticCLI: elasticClient,
}
chatHandler := &handler.Handler{
Upgrader: websocket.Upgrader{},
Service: elasticService,
}
apiServer := handler.ApiServer{
DB: db,
}
//Rotas de consulta
routes.HandleFunc("/api/hackathonUser/{id:[0-9]+}", apiServer.GetHackathonUserHandle).Methods("GET")
routes.HandleFunc("/api/hackathonUser/all", apiServer.GetAllHackathonUsersHandle).Methods("GET")
routes.HandleFunc("/api/hackathon/{id:[0-9]+}", apiServer.GetHackathonHandle).Methods("GET")
routes.HandleFunc("/api/hackathon/all", apiServer.GetAllHackathonsHandle).Methods("GET")
routes.HandleFunc("/api/subscription/{id:[0-9]+}", apiServer.GetSubscriptionHandle).Methods("GET")
routes.HandleFunc("/api/subscription/all", apiServer.GetAllSubscriptionsHandle).Methods("GET")
routes.HandleFunc("/api/user/{id:[0-9]+}", apiServer.GetUserHandle).Methods("GET")
routes.HandleFunc("/api/user/all", apiServer.GetAllUsersHandle).Methods("GET")
//Rotas de criação
routes.HandleFunc("/api/hackathonUser", apiServer.CreateHackathonUserHandle).Methods("POST")
routes.HandleFunc("/api/hackathonUser/user/{id:[0-9]+}", apiServer.CreateByUserIDHandle).Methods("POST")
routes.HandleFunc("/api/hackathonUser/hackathon/{id:[0-9]+}", apiServer.CreateByHackathonIDHandle).Methods("POST")
routes.HandleFunc("/api/hackathon", apiServer.CreateHackathonHandle).Methods("POST")
routes.HandleFunc("/api/login/{email}", apiServer.LoginUserHandle).Methods("POST")
routes.HandleFunc("/api/subscription", apiServer.CreateSubscriptionHandle).Methods("POST")
routes.HandleFunc("/api/user", apiServer.CreateUserHandle).Methods("POST")
var dir string
routes.PathPrefix("/static/").Handler(http.StripPrefix("/", http.FileServer(http.Dir(dir))))
http.Handle("/", routes)
http.HandleFunc("/ws", chatHandler.HandleConnections)
http.HandleFunc("/sendMessage", chatHandler.SendViaPost)
go chatHandler.HandleMessages()
log.Println("http server started on " + os.Getenv("PORT"))
log.Println("database started on " + model.Connection())
log.Println("bonsai started on " + model.ElasticSearch())
error := http.ListenAndServe(":"+os.Getenv("PORT"), nil)
if error != nil {
log.Fatal("ListenAndServe: ", error)
}
}