Help us shape the future of Go! Take the 2026 Go Developer Survey

services

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package services provides the shared service base and a generic operation decorator/builder for CLI (operation) services. It is the operation-oriented counterpart to go/services/service (entity CRUD): Base carries the dependencies every CLI service shares, and Build assembles a decorated interfaces.OpService[A,R] from a single run function.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	// contains filtered or unexported fields
}

Base carries the dependencies common to every CLI service: a name (used as a label in logs, metrics, and decorator actions) and a structured logger that operations use to report progress. Idiosyncratic services embed *Base and read these via the accessors instead of threading them through every call.

func NewBase

func NewBase(name string, log interfaces.Logger) *Base

NewBase constructs a Base with the given name and logger.

func (*Base) Log

func (b *Base) Log() interfaces.Logger

Log returns the structured logger.

func (*Base) Name

func (b *Base) Name() string

Name returns the service name.

type Builder

type Builder[A any, R any] struct {
	// contains filtered or unexported fields
}

Builder assembles a decorated interfaces.OpService[A,R] from a single RunFunc. Decorators are applied inside-out: base run -> logging -> recovery (recovery is ALWAYS outermost).

func Build

func Build[A, R any](run RunFunc[A, R]) *Builder[A, R]

Build starts a fluent builder that assembles a decorated OpService from the given operation function. Dependency injection happens before Build, by closing run over the service's repos; the builder only adds cross-cutting concerns (logging, recovery).

func (*Builder[A, R]) Named

func (b *Builder[A, R]) Named(name string) *Builder[A, R]

Named sets the service name used in log fields and decorator actions.

func (*Builder[A, R]) Service

func (b *Builder[A, R]) Service() interfaces.OpService[A, R]

Service constructs the decorated OpService. Decorators are applied inside-out: base run -> logging -> recovery (recovery is ALWAYS outermost, so it catches panics from every inner decorator and from the operation itself).

func (*Builder[A, R]) WithLog

func (b *Builder[A, R]) WithLog(log interfaces.Logger) *Builder[A, R]

WithLog adds a logging decorator that logs operation entry at Debug level and failures at Error level.

type RunFunc

type RunFunc[A any, R any] func(ctx context.Context, args A) (R, error)

RunFunc is a single service operation: it executes the operation described by args and returns its result. It is the unit the decorator middlewares wrap.

Directories

Path Synopsis
Package service provides BaseService with decorator support for building domain service layers with cross-cutting concerns.
Package service provides BaseService with decorator support for building domain service layers with cross-cutting concerns.
decorators
Package decorators provides fluent decorator composition for services.
Package decorators provides fluent decorator composition for services.

Jump to

Keyboard shortcuts

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