50 lines
1010 B
Go
50 lines
1010 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)
|
|
|
|
if err := c.Run(ctx); err != nil {
|
|
os.Exit(1)
|
|
}
|
|
}
|