Files
spellbook/cmd/main.go
T
abelith 281d7d76d4 chore
- minor refactor
2026-08-08 17:18:34 +05:00

40 lines
796 B
Go

package main
import (
"context"
"database/sql"
"fmt"
"github.com/abelith/spellbook/internal/adapters/caster"
"github.com/abelith/spellbook/internal/adapters/sqlite"
"github.com/abelith/spellbook/internal/application"
"github.com/abelith/spellbook/internal/controllers/cli"
_ "modernc.org/sqlite"
"os"
"os/signal"
"syscall"
)
func handleErr(err error) {
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()
db, err := sql.Open("sqlite", "db.sql")
handleErr(err)
repo := sqlite.NewRepo(db)
handleErr(repo.Init(ctx))
app := application.NewApplication(&caster.SpellCaster{}, repo, repo)
c := cli.NewCLI(app)
handleErr(c.Run(ctx))
}