1package main
2
3import (
4 "context"
5 "flag"
6 "log/slog"
7 "os"
8 "os/signal"
9 "time"
10
11 "git.gabrielgio.me/cerrado/pkg/config"
12 "git.gabrielgio.me/cerrado/pkg/handler"
13 "git.gabrielgio.me/cerrado/pkg/service"
14 "git.gabrielgio.me/cerrado/pkg/worker"
15)
16
17func main() {
18 ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)
19 defer stop()
20 if err := run(ctx); err != nil {
21 slog.Error("Error", "error", err)
22 os.Exit(1)
23 }
24}
25
26func run(ctx context.Context) error {
27 var (
28 configPath = flag.String("config", "/etc/cerrado.scfg", "File path for the configuration file")
29 )
30
31 flag.Parse()
32
33 // repositorie
34 configRepo, err := config.LoadConfigurationRepository(*configPath)
35 if err != nil {
36 return err
37 }
38
39 // services
40 gitService := service.NewGitService(configRepo)
41
42 handler, err := handler.MountHandler(gitService, configRepo)
43 if err != nil {
44 return err
45 }
46
47 serverTask := worker.NewServerTask(configRepo.GetListenAddr(), handler)
48
49 pool := worker.NewTaskPool()
50 pool.AddTask("http-server", 5*time.Second, serverTask)
51
52 return pool.Start(ctx)
53}