cerrado @ 6079b1d963f34ada5c4b25363f2319901e283936

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