-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
serve.go
118 lines (91 loc) · 2.28 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
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
package main
import (
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
cs "github.com/webtor-io/common-services"
s "github.com/webtor-io/rest-api/services"
"net/http"
)
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 = cs.RegisterProbeFlags(c.Flags)
c.Flags = cs.RegisterPprofFlags(c.Flags)
c.Flags = s.RegisterWebFlags(c.Flags)
c.Flags = s.RegisterTorrentStoreFlags(c.Flags)
c.Flags = s.RegisterMagnet2TorrentFlags(c.Flags)
c.Flags = s.RegisterExportFlags(c.Flags)
c.Flags = s.RegisterNodesStatFlags(c.Flags)
}
func serve(c *cli.Context) error {
services := []cs.Servable{}
// Setting Probe
probe := cs.NewProbe(c)
if probe != nil {
services = append(services, probe)
defer probe.Close()
}
// Setting PPROF
pprof := cs.NewPprof(c)
if pprof != nil {
services = append(services, pprof)
defer pprof.Close()
}
// Setting TorrentStore
ts := s.NewTorrentStore(c)
defer ts.Close()
// Setting HTTP Client
httpCl := http.DefaultClient
// Setting CacheMap
cm := s.NewCacheMap(httpCl)
// Setting Magnet2Torrent
m2t := s.NewMagnet2Torrent(c)
defer m2t.Close()
// Setting ResourceMap
rm := s.NewResourceMap(ts, m2t)
// Setting List
li := s.NewList()
// Setting K8SClient
kcl := s.NewK8SClient()
// Setting NodeStat
ns := s.NewNodesStat(c, kcl)
// Setting Subdomains
sd := s.NewSubdomains(ns)
// Setting URLBuilder
ub := s.NewURLBuilder(c, sd, cm)
// Setting DownloadExporter
de := s.NewDownloadExporter(ub)
tb := s.NewTagBuilder(ub, li)
// Setting StreamExporter
se := s.NewStreamExporter(ub, tb)
// Setting TorrentStatExporter
tse := s.NewTorrentStatExporter(ub)
// Setting SubtitlesExporter
vie := s.NewSubtitlesExporter(ub)
// Setting MediaProbeExporter
mpe := s.NewMediaProbeExporter(ub)
// Setting Export
ex := s.NewExport(de, se, tse, vie, mpe)
// Setting Web
web := s.NewWeb(c, rm, li, ex)
if web != nil {
services = append(services, web)
defer web.Close()
}
// Setting Serve
serve := cs.NewServe(services...)
// And SERVE!
err := serve.Serve()
if err != nil {
log.WithError(err).Error("got server error")
}
return err
}