usecase

package
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package usecase provides the application service layer: use cases depend only on domain (errors and port interfaces).

Role in architecture:

  • Application core: handlers call use cases with context; use cases call repository ports and return domain errors.

Responsibilities:

  • Runner: interface for use cases that run with context and return an error (e.g. for handler to map via HandleServiceError).
  • Func: adapter from a function to Runner.
  • GetItemByID: example use case that calls port.GetByID and returns domain.ErrNotFound when not found.

Constraints:

  • Use cases must not import handler, database, redis, or config; only domain and domain/port.
  • No business logic in this package beyond example; real use cases live in the application.

This package must NOT:

  • Perform I/O directly; only through port interfaces.
  • Depend on infrastructure packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetItemByID

func GetItemByID(ctx context.Context, repo port.GetByID, id string) (interface{}, error)

GetItemByID runs the "get item by ID" use case. It depends only on the domain port. Returned error is suitable for handler.HandleServiceError (e.g. domain.ErrNotFound).

Types

type Func

type Func func(ctx context.Context) error

Func adapts a function to the Runner interface.

func (Func) Run

func (f Func) Run(ctx context.Context) error

Run invokes f(ctx).

type Runner

type Runner interface {
	Run(ctx context.Context) error
}

Runner runs a use case with the given context. Return domain.ErrNotFound, domain.ErrUnauthorized, or other errors for the handler to map to HTTP responses via BaseHandler.HandleServiceError.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL