generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
118 lines (102 loc) · 1.9 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
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"context"
"math/rand"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/dogmatiq/browser/analyzer"
"github.com/dogmatiq/browser/githubx"
"github.com/dogmatiq/dodeca/logging"
"github.com/dogmatiq/ferrite"
"github.com/dogmatiq/imbue"
"github.com/google/go-github/v38/github"
)
var (
// version is the current version, set automatically by the makefiles.
version string
// container is the dependency injection container.
container = imbue.New()
)
func init() {
rand.Seed(time.Now().UnixNano())
imbue.With0(
container,
func(
ctx imbue.Context,
) (logging.Logger, error) {
return logging.DebugLogger, nil
},
)
}
func main() {
ferrite.Init()
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer cancel()
g := container.WaitGroup(ctx)
imbue.Go2(
g,
func(
ctx context.Context,
o *analyzer.Orchestrator,
l logging.Logger,
) error {
for {
if err := o.Run(ctx); err != nil {
if err == context.Canceled {
return err
}
logging.LogString(l, err.Error())
}
}
},
)
imbue.Go2(
g,
func(
ctx context.Context,
c *githubx.Connector,
o *analyzer.Orchestrator,
) error {
return githubx.ListInstallations(
ctx,
c.AppClient,
func(ctx context.Context, i *github.Installation) error {
ic, err := c.InstallationClient(ctx, i.GetID())
if err != nil {
return err
}
return githubx.ListRepos(
ctx,
ic,
func(ctx context.Context, r *github.Repository) error {
return o.EnqueueAnalyis(ctx, r.GetID())
},
)
},
)
},
)
imbue.Go1(
g,
func(
ctx context.Context,
h http.Handler,
) error {
s := http.Server{
Addr: ":8080",
Handler: h,
}
go func() {
<-ctx.Done()
s.Close()
}()
return s.ListenAndServe()
},
)
if err := g.Wait(); err != nil {
panic(err)
}
}