Files
spellbook/cmd/main.go
T
abelith a8f164c241 feat
- configuration
2026-08-08 17:40:47 +05:00

48 lines
981 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/config"
"github.com/abelith/spellbook/internal/controllers/cli"
_ "modernc.org/sqlite"
"os"
"os/signal"
"path/filepath"
"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()
cfg, err := config.NewConfig()
handleErr(err)
dir := filepath.Dir(cfg.DBPath)
handleErr(os.MkdirAll(dir, 0755))
db, err := sql.Open("sqlite", cfg.DBPath)
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))
}