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 ¶
var AppGraph = loom.Graph[*Application]( loom.WithContext(), loom.Provide(NewConfig), loom.Provide(NewLogger), ServiceModule, loom.Provide(NewHTTPServer), loom.Provide(NewApplication), loom.Supply(AppName("full")), )
AppGraph wires the application.
var DatabaseModule = loom.Module( loom.Provide(NewDatabase), loom.Provide(NewRepository[User]), loom.Provide(NewRepository[Article]), )
DatabaseModule groups everything that talks to storage. Modules are sets: including one twice has no effect.
var ServiceModule = loom.Module( DatabaseModule, loom.As[UserStore](NewUserStore), loom.Provide(NewUserService), loom.Provide(NewArticleService), )
ServiceModule groups the service layer. It nests DatabaseModule.
var WorkerGraph = loom.Graph[*Worker]( loom.Provide(NewConfig), loom.Provide(NewLogger), loom.Provide(NewDatabase), loom.Provide(NewWorker), )
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 NewApplication ¶
func NewApplication( name AppName, cfg *Config, log *Logger, db *Database, server *HTTPServer, users *UserService, articles *ArticleService, ) *Application
NewApplication builds the application.
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 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 Repository ¶
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 UserService ¶
UserService contains user business logic.
func NewUserService ¶
func NewUserService(store UserStore, log *Logger) *UserService
NewUserService builds the user service.
type Worker ¶
Worker is a second build target that shares providers with the application.
func InitWorker ¶
InitWorker builds *Worker from the graph declared by WorkerGraph.