-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.go
63 lines (52 loc) · 1.19 KB
/
serve.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
package main
import (
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
cs "github.com/webtor-io/common-services"
s "github.com/webtor-io/webhook/services"
)
func makeServeCMD() cli.Command {
serveCmd := cli.Command{
Name: "serve",
Aliases: []string{"s"},
Usage: "Serves web server",
Action: serve,
}
configureServe(&serveCmd)
return serveCmd
}
func configureServe(c *cli.Command) {
c.Flags = s.RegisterWebFlags([]cli.Flag{})
c.Flags = cs.RegisterProbeFlags(c.Flags)
c.Flags = s.RegisterPatreonFlags(c.Flags)
c.Flags = cs.RegisterPGFlags(c.Flags)
}
func serve(c *cli.Context) error {
// Setting DB
db := cs.NewPG(c)
defer db.Close()
// Setting Migrations
m := cs.NewPGMigration(db)
err := m.Run()
if err != nil {
return err
}
// Setting ProbeService
probe := cs.NewProbe(c)
defer probe.Close()
// Setting WebService
web := s.NewWeb(c)
defer web.Close()
// Setting Patreon
patreon := s.NewPatreon(c, db)
// Registering Patreon handler
web.RegisterProvider("/patreon", patreon.Handle)
// Setting ServeService
serve := cs.NewServe(probe, web)
// And SERVE!
err = serve.Serve()
if err != nil {
log.WithError(err).Error("Got server error")
}
return err
}