forked from ARGOeu/argo-messaging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (43 loc) · 1.55 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
package main
import (
"crypto/tls"
"net/http"
"strconv"
"github.com/ARGOeu/argo-messaging/brokers"
"github.com/ARGOeu/argo-messaging/config"
"github.com/ARGOeu/argo-messaging/push"
"github.com/ARGOeu/argo-messaging/stores"
log "github.com/Sirupsen/logrus"
"github.com/gorilla/handlers"
)
func main() {
// create and load configuration object
cfg := config.NewAPICfg("LOAD")
// create the store
store := stores.NewMongoStore(cfg.StoreHost, cfg.StoreDB)
store.Initialize()
// create and initialize broker based on configuration
broker := brokers.NewKafkaBroker(cfg.GetZooList())
defer broker.CloseConnections()
sndr := push.NewHTTPSender(1)
mgr := push.NewManager(broker, store, sndr)
mgr.LoadPushSubs()
mgr.StartAll()
// create and initialize API routing object
API := NewRouting(cfg, broker, store, mgr, defaultRoutes)
//Configure TLS support only
config := &tls.Config{
MinVersion: tls.VersionTLS10,
PreferServerCipherSuites: true,
}
// Initialize CORS specifics
xReqWithConType := handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type"})
allowVerbs := handlers.AllowedMethods([]string{"OPTIONS", "POST", "GET", "PUT", "DELETE", "HEAD"})
// Initialize server wth proper parameters
server := &http.Server{Addr: ":" + strconv.Itoa(cfg.Port), Handler: handlers.CORS(xReqWithConType, allowVerbs)(API.Router), TLSConfig: config}
// Web service binds to server. Requests served over HTTPS.
err := server.ListenAndServeTLS(cfg.Cert, cfg.CertKey)
if err != nil {
log.Fatal("API", "\t", "ListenAndServe:", err)
}
}