-
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathmain.go
More file actions
87 lines (73 loc) · 1.67 KB
/
main.go
File metadata and controls
87 lines (73 loc) · 1.67 KB
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
package main
import (
"context"
"embed"
"flag"
"log/slog"
"os"
"github.com/robherley/snips.sh/internal/app"
"github.com/robherley/snips.sh/internal/config"
"github.com/robherley/snips.sh/internal/logger"
"github.com/robherley/snips.sh/internal/stats"
"github.com/robherley/snips.sh/internal/web"
)
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 {
slog.Error("unable to load config", "err", err)
os.Exit(1)
}
if cfg.Debug {
logger.Initialize(slog.LevelDebug)
}
statsd, err := stats.Initialize(cfg.Metrics.Statsd, cfg.Metrics.UseDogStatsd)
if err != nil {
slog.Error("unable to initialize metrics", "err", err)
os.Exit(1)
}
usage := flag.Bool("usage", false, "print environment variable usage")
flag.Parse()
if usage != nil && *usage {
_ = cfg.PrintUsage()
return
}
assets, err := web.NewAssets(
&webFS,
&docsFS,
readme,
cfg.HTML.ExtendHeadFile,
)
if err != nil {
slog.Error("failed to load assets", "err", err)
os.Exit(1)
}
application, err := app.New(cfg, assets)
if err != nil {
slog.Error("failed to load config", "err", err)
os.Exit(1)
}
application.OnShutdown = func(_ context.Context) {
statsd.Shutdown()
}
if err := application.DB.Migrate(context.Background()); err != nil {
slog.Error("failed to migrate database", "err", err)
os.Exit(1)
}
slog.Info("starting snips.sh",
"ssh_addr", cfg.SSH.Internal.String(),
"http_addr", cfg.HTTP.Internal.String(),
)
if err := application.Boot(); err != nil {
slog.Error("failed to load config", "err", err)
os.Exit(1)
}
}