full

package
v0.3.2 Latest Latest
Warning

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

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

Documentation

Overview

Package full is the end-to-end loom example: generics, an interface binding, modules, supply, lifecycle hooks, and constructor cleanups in one graph.

Index

Constants

This section is empty.

Variables

AppGraph wires the application.

DatabaseModule groups everything that talks to storage. Modules are sets: including one twice has no effect.

ServiceModule groups the service layer. It nests DatabaseModule.

WorkerGraph is a second target in the same package. It produces InitWorker.

Functions

func NewUserStore

func NewUserStore(repo *Repository[User], log *Logger) *userStore

NewUserStore returns the concrete implementation of UserStore.

Types

type AppName

type AppName string

AppName is an existing value supplied to the graph rather than constructed.

type Application

type Application struct {
	Name     AppName
	Config   *Config
	Logger   *Logger
	Database *Database
	Server   *HTTPServer
	Users    *UserService
	Articles *ArticleService
}

Application is the assembled program.

func InitApp

func InitApp(ctx context.Context) (*Application, *loom.Lifecycle, error)

InitApp builds *Application from the graph declared by AppGraph.

func NewApplication

func NewApplication(
	name AppName,
	cfg *Config,
	log *Logger,
	db *Database,
	server *HTTPServer,
	users *UserService,
	articles *ArticleService,
) *Application

NewApplication builds the application.

type Article

type Article struct {
	ID    int64
	Title string
}

Article is a domain entity.

type ArticleService

type ArticleService struct {
	Repo *Repository[Article]
	Log  *Logger
}

ArticleService contains article business logic.

func NewArticleService

func NewArticleService(repo *Repository[Article], log *Logger) *ArticleService

NewArticleService builds the article service.

type Config

type Config struct {
	Addr     string
	DSN      string
	LogLevel string
}

Config holds static configuration.

func NewConfig

func NewConfig() *Config

NewConfig loads configuration.

type Database

type Database struct {
	DSN    string
	Closed bool
}

Database is a resource owned by a constructor cleanup.

func NewDatabase

func NewDatabase(cfg *Config) (*Database, loom.Cleanup, error)

NewDatabase dials the database. It needs a context, which the graph makes available with loom.WithContext().

type HTTPServer

type HTTPServer struct {
	Addr    string
	Log     *Logger
	Users   *UserService
	Running bool
}

HTTPServer is a long-lived service with start/stop hooks.

func NewHTTPServer

func NewHTTPServer(lc *loom.Lifecycle, cfg *Config, log *Logger, users *UserService) *HTTPServer

NewHTTPServer builds the server and registers its lifecycle hooks.

type Logger

type Logger struct {
	Level string
}

Logger is a tiny structured logger.

func NewLogger

func NewLogger(cfg *Config) *Logger

NewLogger builds the logger from configuration.

type Repository

type Repository[T any] struct {
	DB *Database
}

Repository is generic over the entity it stores.

func NewRepository

func NewRepository[T any](db *Database) *Repository[T]

NewRepository builds a repository for T.

type User

type User struct {
	ID   int64
	Name string
}

User is a domain entity.

type UserService

type UserService struct {
	Store UserStore
	Log   *Logger
}

UserService contains user business logic.

func NewUserService

func NewUserService(store UserStore, log *Logger) *UserService

NewUserService builds the user service.

type UserStore

type UserStore interface {
	Find(ctx context.Context, id int64) (*User, error)
}

UserStore is the persistence boundary the services depend on.

type Worker

type Worker struct {
	DB  *Database
	Log *Logger
}

Worker is a second build target that shares providers with the application.

func InitWorker

func InitWorker() (*Worker, *loom.Lifecycle, error)

InitWorker builds *Worker from the graph declared by WorkerGraph.

func NewWorker

func NewWorker(db *Database, log *Logger) *Worker

NewWorker builds the worker.

Jump to

Keyboard shortcuts

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