Repository navigation
Expand file tree
/
Copy pathserve.go
More file actions
122 lines (101 loc) · 2.38 KB
/
Copy pathserve.go
File metadata and controls
122 lines (101 loc) · 2.38 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"net/http"
"time"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
cs "github.com/webtor-io/common-services"
"github.com/webtor-io/vault/services"
)
func configureServe(c *cli.Command) {
c.Flags = cs.RegisterProbeFlags(c.Flags)
c.Flags = cs.RegisterPprofFlags(c.Flags)
c.Flags = cs.RegisterPromFlags(c.Flags)
c.Flags = cs.RegisterPGFlags(c.Flags)
c.Flags = cs.RegisterS3ClientFlags(c.Flags)
c.Flags = services.RegisterWebFlags(c.Flags)
c.Flags = services.RegisterWorkerFlags(c.Flags)
c.Flags = services.RegisterApiFlags(c.Flags)
c.Flags = services.RegisterMetricsFlags(c.Flags)
c.Flags = cs.RegisterNATSFlags(c.Flags)
}
func makeServeCMD() cli.Command {
serveCmd := cli.Command{
Name: "serve",
Aliases: []string{"s"},
Usage: "Serves web server",
Action: serve,
}
configureServe(&serveCmd)
return serveCmd
}
func serve(c *cli.Context) (err error) {
// Setting DB
pg := cs.NewPG(c)
if pg != nil {
defer pg.Close()
}
// Setting Migrations
m := cs.NewPGMigration(pg)
err = m.Run()
if err != nil {
return err
}
var svcs []cs.Servable
// Setting Probe
probe := cs.NewProbe(c)
if probe != nil {
svcs = append(svcs, probe)
defer probe.Close()
}
// Setting PPROF
pprof := cs.NewPprof(c)
if pprof != nil {
svcs = append(svcs, pprof)
defer pprof.Close()
}
// Setting Prometheus exporter (/metrics on :8083 by default)
prom := cs.NewProm(c)
if prom != nil {
svcs = append(svcs, prom)
defer prom.Close()
}
// Setting vault metrics refresher — populates gauges consumed by prom
metrics := services.NewMetrics(c, pg)
svcs = append(svcs, metrics)
defer metrics.Close()
cl := &http.Client{
Timeout: 30 * time.Minute,
}
// Setting S3Client
s3c := cs.NewS3Client(c, cl)
// Setting Web
web := services.NewWeb(c, pg, s3c)
svcs = append(svcs, web)
defer web.Close()
// Setting Webtor Rest API
api := services.NewApi(c, cl)
// Setting NATS
nt := cs.NewNATS(c)
if nt != nil {
defer nt.Close()
}
// Setting Worker
worker := services.NewWorker(c, pg, s3c, api, nt)
svcs = append(svcs, worker)
defer worker.Close()
// Setting EventHandler
events := services.NewEventHandler(pg, nt)
if events != nil {
svcs = append(svcs, events)
defer events.Close()
}
// Setting Serve
s := cs.NewServe(svcs...)
// And SERVE!
err = s.Serve()
if err != nil {
log.WithError(err).Error("got server error")
}
return
}