-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
executable file
·106 lines (102 loc) · 3.37 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"crypto/tls"
"flag"
"net/http"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
_ "github.com/lib/pq"
"github.com/sirupsen/logrus"
filter "github.com/ticketmaster/authentication/gin"
"github.com/ticketmaster/lbapi/common"
"github.com/ticketmaster/lbapi/config"
"github.com/ticketmaster/lbapi/env"
"github.com/ticketmaster/lbapi/golog"
"github.com/ticketmaster/lbapi/handler"
"github.com/ticketmaster/lbapi/routeconfig"
)
func main() {
////////////////////////////////////////////////////////////////////////////
var err error
env.Set()
flag.Parse()
log := logrus.New()
////////////////////////////////////////////////////////////////////////////
err = common.SetSources()
if err != nil {
log.Fatal(err)
}
log.Println("Load Balancer Sources enumerated.")
////////////////////////////////////////////////////////////////////////////
options := filter.NewAuthenticationOptions()
options.ConfigPath = "etc"
////////////////////////////////////////////////////////////////////////////
router := gin.New()
corsConfig := cors.DefaultConfig()
if len(config.GlobalConfig.Lbm.CorsAllowedOrigins) > 0 {
corsConfig.AllowOrigins = config.GlobalConfig.Lbm.CorsAllowedOrigins
} else {
corsConfig.AllowOrigins = []string{"http://localhost"}
}
corsConfig.AllowCredentials = true
corsConfig.AllowHeaders = []string{"Authorization", "Content-Type", "Cache-Control", "Pragma"}
router.Use(cors.New(corsConfig))
////////////////////////////////////////////////////////////////////////////
err = filter.UseAuthentication(router, options)
if err != nil {
log.Fatal(err)
}
////////////////////////////////////////////////////////////////////////////
router.Use(golog.Logger(log))
router.HEAD("/", func(c *gin.Context) {})
router.GET("/", func(c *gin.Context) {})
////////////////////////////////////////////////////////////////////////////
v1 := router.Group("/api/v1")
////////////////////////////////////////////////////////////////////////////
l := routeconfig.NewLoadBalancer()
_, err = handler.New(l, v1)
if err != nil {
log.Fatal(err)
}
v := routeconfig.NewVirtualServer()
_, err = handler.New(v, v1)
if err != nil {
log.Fatal(err)
}
r := routeconfig.NewRecycle()
_, err = handler.New(r, v1)
if err != nil {
log.Fatal(err)
}
s := routeconfig.NewStatus()
_, err = handler.New(s, v1)
if err != nil {
log.Fatal(err)
}
////////////////////////////////////////////////////////////////////////////
if config.GlobalConfig.Lbm.RunTLS {
server := http.Server{
Addr: ":8443",
Handler: router,
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler), 0),
TLSConfig: &tls.Config{
MinVersion: tls.VersionTLS12,
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
PreferServerCipherSuites: true,
CipherSuites: []uint16{
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
},
},
}
logrus.Fatal(server.ListenAndServeTLS("etc/"+config.GlobalConfig.Lbm.PemFile, "etc/"+config.GlobalConfig.Lbm.KeyFile))
} else {
server := http.Server{
Addr: ":8080",
Handler: router,
}
log.Fatal(server.ListenAndServe())
}
}