-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
main.go
77 lines (64 loc) · 1.65 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
package main
import (
"context"
"embed"
"flag"
"github.com/robherley/snips.sh/internal/app"
"github.com/robherley/snips.sh/internal/config"
"github.com/robherley/snips.sh/internal/http"
"github.com/robherley/snips.sh/internal/logger"
"github.com/robherley/snips.sh/internal/stats"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
var (
//go:embed web/*
webFS embed.FS
//go:embed README.md
readme []byte
//go:embed docs/*.md
docsFS embed.FS
)
func main() {
logger.Initialize()
cfg, err := config.Load()
if err != nil {
log.Fatal().Err(err).Msg("unable to load config")
}
statsd, err := stats.Initialize(cfg.Metrics.Statsd, cfg.Metrics.UseDogStatsd)
if err != nil {
log.Fatal().Err(err).Msg("unable to initialize metrics")
}
if cfg.Debug {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
usage := flag.Bool("usage", false, "print environment variable usage")
flag.Parse()
if usage != nil && *usage {
_ = cfg.PrintUsage()
return
}
assets, err := http.NewAssets(
&webFS,
&docsFS,
readme,
cfg.HTML.ExtendHeadFile,
)
if err != nil {
log.Fatal().Err(err).Msg("failed to load assets")
}
application, err := app.New(cfg, assets)
if err != nil {
log.Fatal().Err(err).Msg("failed to load config")
}
application.OnShutdown = func(_ context.Context) {
statsd.Shutdown()
}
if err := application.DB.Migrate(context.Background()); err != nil {
log.Fatal().Err(err).Msg("failed to migrate database")
}
log.Info().Str("ssh_addr", cfg.SSH.Internal.String()).Str("http_addr", cfg.HTTP.Internal.String()).Msg("starting snips.sh")
if err := application.Boot(); err != nil {
log.Fatal().Err(err).Msg("failed to load config")
}
}