-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
configure.go
68 lines (57 loc) · 1.48 KB
/
configure.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
package main
import (
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
cs "github.com/webtor-io/common-services"
s "github.com/webtor-io/torrent-archiver/services"
"net/http"
)
func configure(app *cli.App) {
app.Flags = []cli.Flag{}
app.Flags = cs.RegisterProbeFlags(app.Flags)
app.Flags = cs.RegisterPprofFlags(app.Flags)
app.Flags = cs.RegisterPromFlags(app.Flags)
app.Flags = s.RegisterWebFlags(app.Flags)
app.Flags = s.RegisterTorrentStoreClientFlags(app.Flags)
app.Action = run
}
func run(c *cli.Context) error {
var services []cs.Servable
// Setting ProbeService
probe := cs.NewProbe(c)
if probe != nil {
services = append(services, probe)
defer probe.Close()
}
// Setting PprofService
pprof := cs.NewPprof(c)
if pprof != nil {
services = append(services, pprof)
defer pprof.Close()
}
// Setting PromService
prom := cs.NewProm(c)
if prom != nil {
services = append(services, prom)
defer prom.Close()
}
// Setting TorrentStoreCLient
torrentStoreClient := s.NewTorrentStoreClient(c)
defer torrentStoreClient.Close()
// Setting TorrentStore
torrentStore := s.NewTorrentStore(torrentStoreClient)
// Setting HTTP Client
httpClient := http.DefaultClient
// Setting WebService
web := s.NewWeb(c, torrentStore, httpClient)
services = append(services, web)
defer web.Close()
// Setting ServeService
serve := cs.NewServe(services...)
// And SERVE!
err := serve.Serve()
if err != nil {
log.WithError(err).Error("got server error")
}
return err
}