Files
GL/cmd/gl/main.go
T

57 lines
1.5 KiB
Go

package main
import (
"context"
"flag"
"log/slog"
"os"
"os/signal"
"syscall"
"gl/application/health"
applicationledger "gl/application/ledger"
"gl/infrastructure/config"
"gl/infrastructure/observability"
"gl/infrastructure/postgres"
grpcadapter "gl/interface/grpc"
)
func main() {
observability.Configure("gl", slog.LevelInfo)
configPath := flag.String("conf", "./gl.cfg.toml", "path to the TOML configuration file")
flag.Parse()
cfg, err := config.Load(*configPath)
if err != nil {
slog.Error("load configuration", "error", err)
os.Exit(1)
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
database, err := postgres.Open(ctx, cfg.Database)
if err != nil {
slog.Error("open GL database", "error", err)
os.Exit(1)
}
defer database.Close()
if err := postgres.Migrate(ctx, database); err != nil {
slog.Error("migrate GL database", "error", err)
os.Exit(1)
}
repository := postgres.NewJournalRepository(database)
handler := grpcadapter.NewHandler(health.NewService(database), applicationledger.NewService(repository, nil))
slog.Info("starting GL gRPC service", "host", cfg.GRPC.Host, "port", cfg.GRPC.Port)
serverConfig := grpcadapter.ServerConfig{
Host: cfg.GRPC.Host,
Port: cfg.GRPC.Port,
ShutdownTimeout: cfg.GRPC.ShutdownTimeout,
}
if err := grpcadapter.Run(ctx, serverConfig, handler); err != nil {
slog.Error("GL service stopped", "error", err)
os.Exit(1)
}
}