/
main.go
55 lines (45 loc) · 1.32 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
package main
import (
"context"
"os"
"time"
"github.com/markbates/pkger"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/lobsterdore/release-dash/cache"
"github.com/lobsterdore/release-dash/config"
"github.com/lobsterdore/release-dash/scm"
"github.com/lobsterdore/release-dash/web"
)
func main() {
_ = pkger.Include("/web/templates")
_ = pkger.Include("/web/static")
log.Log().Msg("Reading config")
cfg, err := config.NewConfig()
if err != nil {
log.Fatal().Err(err).Msg("Unable to retrieve configuration")
os.Exit(3)
}
zLevel, err := zerolog.ParseLevel(cfg.Logging.Level)
if err == nil {
zerolog.SetGlobalLevel(zLevel)
} else {
log.Error().Err(err).Msgf("Could not get and set log level %s, using default", cfg.Logging.Level)
}
log.Log().Msg("Starting server")
ctx, cancel := context.WithTimeout(
context.Background(),
time.Duration(cfg.Server.Timeout.Server)*time.Second,
)
defer cancel()
githubAdapter, err := scm.NewGithubAdapter(ctx, cfg.Github.Pat, cfg.Github.UrlDefault, cfg.Github.UrlUpload)
if err != nil {
log.Fatal().Err(err).Msg("Unable to setup Github client")
os.Exit(3)
}
localCacheAdapter := cache.NewLocalCacheAdapter(
cfg.Cache.DefaultExpirationSeconds,
cfg.Cache.CleanupIntervalSeconds,
)
web.NewWeb(cfg, ctx, githubAdapter, localCacheAdapter).Run(ctx)
}