-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
85 lines (68 loc) · 2.18 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
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"crypto/tls"
"net/http"
"strconv"
"github.com/ARGOeu/argo-messaging/brokers"
"github.com/ARGOeu/argo-messaging/config"
oldPush "github.com/ARGOeu/argo-messaging/push"
push "github.com/ARGOeu/argo-messaging/push/grpc/client"
"github.com/ARGOeu/argo-messaging/stores"
"github.com/ARGOeu/argo-messaging/version"
"github.com/gorilla/handlers"
log "github.com/sirupsen/logrus"
)
func init() {
// don't use colors in output
log.SetFormatter(
&log.TextFormatter{
FullTimestamp: true,
DisableColors: true},
)
// display binary version information during start up
version.LogInfo()
}
func main() {
// create and load configuration object
cfg := config.NewAPICfg("LOAD")
// create the store
store := stores.NewMongoStoreWithOfficialDriver(cfg.StoreHost, cfg.StoreDB)
store.Initialize()
// create and initialize broker based on configuration
broker := brokers.NewKafkaBroker(cfg.GetBrokerInfo())
mgr := &oldPush.Manager{}
// ams push server pushClient
pushClient := push.NewGrpcClient(cfg)
err := pushClient.Dial()
if err != nil {
log.WithFields(
log.Fields{
"type": "backend_log",
"backend_service": "ams-push-server",
"backend_hosts": pushClient.Target(),
},
).Error(err.Error())
}
defer func() {
store.Close()
broker.CloseConnections()
pushClient.Close()
}()
// create and initialize API routing object
API := NewRouting(cfg, broker, store, mgr, pushClient, defaultRoutes)
//Configure TLS support only
config := &tls.Config{
MinVersion: tls.VersionTLS12,
PreferServerCipherSuites: true,
}
// Initialize CORS specifics
xReqWithConType := handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "x-api-key"})
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)
}
}