- application struct
This commit is contained in:
abelith committed 2026-08-03 04:49:59 +05:00
1 parent 7c1a49f457
commit 478ac2fc7b
3 files changed
+106

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
package application
import (
"context"
"spellbook/internal/models"
)
type SpellCaster interface {
Cast(ctx context.Context, cast models.SpellCast) (models.CastResult, error)
}
type SpellCommand interface {
Add(ctx context.Context, spell models.Spell) error
Delete(ctx context.Context, spellName string) error
}
type SpellQuery interface {
Get(ctx context.Context, spellName string) (models.Spell, error)
GetMany(ctx context.Context, query models.SearchQuery) ([]models.Spell, error)
}
type Application struct {
caster SpellCaster
spellCmd SpellCommand
spellQuery SpellQuery
}
func (a *Application) AddSpell(
ctx context.Context,
spell models.Spell,
) error {
return a.spellCmd.Add(ctx, spell)
}
func (a *Application) GetSpell(
ctx context.Context,
spellName string,
) (models.Spell, error) {
return a.spellQuery.Get(ctx, spellName)
}
func (a *Application) GetSpells(
ctx context.Context,
query models.SearchQuery,
) ([]models.Spell, error) {
return a.spellQuery.GetMany(ctx, query)
}
func (a *Application) DeleteSpell(
ctx context.Context,
spellName string,
) error {
return a.spellCmd.Delete(ctx, spellName)
}
func (a *Application) CastSpell(
ctx context.Context,
spellCast models.SpellCast,
) (models.CastResult, error) {
return a.caster.Cast(ctx, spellCast)
}
+14
View File
@@ -0,0 +1,14 @@
package handlers
import (
"context"
"spellbook/internal/models"
)
type Application interface {
AddSpell(ctx context.Context, spell models.Spell) error
GetSpell(ctx context.Context, spellName string) (models.Spell, error)
GetSpells(ctx context.Context, query models.SearchQuery) ([]models.Spell, error)
DeleteSpell(ctx context.Context, spellName string) error
CastSpell(ctx context.Context, spellCast models.SpellCast) (models.CastResult, error)
}
+31
View File
@@ -0,0 +1,31 @@
package models
import (
"io"
"time"
)
type Spell struct {
Name string
Spell string
Tags []string
}
type SpellCast struct {
Spell Spell
Args map[string]string
Stdout io.Writer
Stderr io.Writer
}
type CastResult struct {
ExitCode int
Duration time.Duration
Meta map[string]any
}
type SearchQuery struct {
Cursor int
Limit int
Tags []string
}