Documentation
¶
Overview ¶
Package service is the service tier: a Base is the embeddable core of a consumer's service, running its custom operations through the tier's decoration (Tier) with the promoted Exec, and building the decorated CRUD services and single-operation services the tier offers. Every service it builds is a core interface.
Index ¶
- func Op[In, Out any](b Base, op string, fn func(ctx context.Context, in In) (Out, error)) decorate.OpFunc[In, Out]
- func Tier() decorate.Tier
- type Base
- func (b Base) CRUD[T, P any, ID comparable](repo interfaces.Repository[T, P, ID], validate func(*T) error) interfaces.Service[T, P, ID]
- func (b Base) CRUDNoList[T any, ID comparable](repo interfaces.CRUDNoListRepository[T, ID], validate func(*T) error) interfaces.CRUDNoListRepository[T, ID]
- func (b Base) OpService[A, R any](run func(ctx context.Context, args A) (R, error)) interfaces.OpService[A, R]
- func (b Base) Resource[T, P any, ID comparable, C, U any](repo interfaces.Resource[T, P, ID, C, U], v Validators[C, U]) interfaces.Resource[T, P, ID, C, U]
- type Validators
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Op ¶ added in v0.0.12
func Op[In, Out any]( b Base, op string, fn func(ctx context.Context, in In) (Out, error), ) decorate.OpFunc[In, Out]
Op is the service's named operation, run through the service tier. An input that implements interfaces.Validatable is validated first, and an invalid one returns its validation error without running fn.
Types ¶
type Base ¶ added in v0.0.7
Base is the embeddable core of a service named by its Subject: Name and Exec run a custom operation through the tier's decoration, and Op builds its named operations, each under its own decoration name. The zero Base runs operations undecorated.
func NewBase ¶ added in v0.0.7
NewBase builds the Base for the service named name, decorated with deps; its named operations share deps.
func NewBaseFrom ¶ added in v0.0.12
func NewBaseFrom(decs decorate.Decorations, name string) (Base, error)
NewBaseFrom builds the Base for the service named name, decorated from decs: the service as the service-tier component name, and each named operation op as name+"."+op. A decoration that fails to resolve is CodeInvalidInput.
func (Base) CRUD ¶ added in v0.0.7
func (b Base) CRUD[T, P any, ID comparable]( repo interfaces.Repository[T, P, ID], validate func(*T) error, ) interfaces.Service[T, P, ID]
CRUD is the decorated service over repo: every operation runs through the service's decoration, and a non-nil validate rejects an invalid entity before Create or Update.
func (Base) CRUDNoList ¶ added in v0.0.7
func (b Base) CRUDNoList[T any, ID comparable]( repo interfaces.CRUDNoListRepository[T, ID], validate func(*T) error, ) interfaces.CRUDNoListRepository[T, ID]
CRUDNoList is CRUD for a resource with no listable collection.
func (Base) OpService ¶ added in v0.0.7
func (b Base) OpService[A, R any]( run func(ctx context.Context, args A) (R, error), ) interfaces.OpService[A, R]
OpService is the decorated single-operation service whose Run runs run as the "Run" operation.
func (Base) Resource ¶ added in v0.0.11
func (b Base) Resource[T, P any, ID comparable, C, U any]( repo interfaces.Resource[T, P, ID, C, U], v Validators[C, U], ) interfaces.Resource[T, P, ID, C, U]
Resource is the decorated service over repo, a resource whose Create takes C and whose Update takes U: every role runs through the service's decoration, and v rejects an invalid write input before it reaches repo.
type Validators ¶ added in v0.0.11
type Validators[C, U any] struct { // Create checks a Create input. Create func(C) error // Update checks an Update input. Update func(U) error }
Validators check a Resource's write inputs before they reach the repository; a nil validator accepts every input.