Documentation
¶
Index ¶
- Constants
- type Metadata
- type Note
- type Repository
- type Service
- func (s *Service) Begin(ctx context.Context) (Transaction, error)
- func (s *Service) DeleteNote(ctx context.Context, id string) error
- func (s *Service) GetNote(ctx context.Context, id string) (Note, error)
- func (s *Service) ListNotes(ctx context.Context) ([]Note, error)
- func (s *Service) SaveNote(ctx context.Context, id string, content string, meta Metadata) error
- type Syncable
- type Transaction
- type TransactionalRepository
Constants ¶
const ChangeReasonKey contextKey = "change_reason"
ChangeReasonKey is the context key for passing specific change reasons (commit messages) during Save/Delete operations.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Note ¶
Note is the central entity of the domain. It represents a piece of knowledge identified by an ID. It is agnostic to storage format (Markdown, JSON, SQL).
type Repository ¶
type Repository interface {
// Save persists a note. It creates if not exists, or updates if it does.
Save(ctx context.Context, n Note) error
// Get retrieves a note by its ID.
Get(ctx context.Context, id string) (Note, error)
// List returns all available notes.
// TODO: Add pagination or filtering options in the future.
List(ctx context.Context) ([]Note, error)
// Delete removes a note by its ID.
Delete(ctx context.Context, id string) error
// Initialize ensures the underlying storage is ready (e.g., create directories, git init, schema migration).
Initialize(ctx context.Context) error
}
Repository defines the contract for storing and retrieving notes. Adhering to this interface allows the core to be independent of the underlying storage mechanism (Filesystem, Git, SQL, S3, etc).
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service encapsulates the business logic for managing notes.
func NewService ¶
func NewService(r Repository, l *slog.Logger) *Service
NewService creates a new Service instance.
func (*Service) Begin ¶
func (s *Service) Begin(ctx context.Context) (Transaction, error)
Begin starts a new unit of work (transaction). It returns an error if the underlying repository does not support transactions.
func (*Service) DeleteNote ¶
DeleteNote deletes a note by ID.
type Syncable ¶
type Syncable interface {
// Sync synchronizes the local state with a remote source (e.g. git pull/push).
Sync(ctx context.Context) error
}
Syncable defines an interface for repositories that support synchronization with a remote.
type Transaction ¶
type Transaction interface {
// Save stages a note for persistence.
Save(ctx context.Context, n Note) error
// Get retrieves a note, preferring the staged version if it exists in the transaction.
Get(ctx context.Context, id string) (Note, error)
// List returns all available notes, including staged ones.
List(ctx context.Context) ([]Note, error)
// Delete stages a note for removal.
Delete(ctx context.Context, id string) error
// Commit applies all staged changes atomically.
Commit(ctx context.Context, changeReason string) error
// Rollback discards all staged changes.
Rollback(ctx context.Context) error
}
Transaction defines the contract for a unit of work. Changes made within a transaction are atomic and isolated (depending on implementation).
type TransactionalRepository ¶
type TransactionalRepository interface {
Repository
// Begin starts a new transaction.
Begin(ctx context.Context) (Transaction, error)
}
TransactionalRepository extends Repository to support transactions.