boot

package
v0.0.0-...-a7ad5ca Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 54 Imported by: 0

README

Boot

internal/boot is the composition root. It owns process startup, configured infrastructure resources, samber/do dependency injection, and business route mounting.

Business modules declare what they provide and what they mount:

func accessModule() Module {
	return NewModule("access",
		Provide(newAccessStore),
		Provide(newAccessUsecase),
		Provide(newAccessHandler),
		Route(accesshttp.Register),
	)
}

Provider functions are ordinary do.Provider[T] functions. Runtime business storage uses the configured MySQL resource:

func newAccessStore(i do.Injector) (*accessmysql.Store, error) {
	ctx, db, err := startupMySQL(i)
	if err != nil {
		return nil, err
	}
	return accessmysql.NewStore(ctx, db)
}

Business code lives under internal/modules/<module>. Platform runtime code lives under internal/platform. Boot is allowed to import adapters, infrastructure, server, and configs so usecase and domain packages stay clean.

Cross-module wiring belongs here. For example, auth defines the small authorization reader, recorder, and login-session interfaces it needs; boot bridges its authorization reader to the access usecase, passes the concrete identity/auth MySQL stores, and bridges login records into the audit usecase. Access also receives a small identity reader so role delegation and runtime authorization can use current administrator state without importing the identity adapter directly. Settings receives a version-catalog bridge for access-owned menus only; Managed API Route definitions cannot travel through version bundles. API token authentication is wired here through a small server-facing verifier adapter, so internal/platform/server can accept X-API-Token without importing token storage. Browser Login Session authentication is wired the same way. System First Initialization coordinates one transaction across setup, access, identity, and settings stores to create the root authorization baseline, first administrator, initial settings, and completion marker.

Access owns Casbin RBAC, current authorization views, and exact Managed API Route decisions. Boot first mounts every module, then finalizes route exposure from Echo's registered route table and installs one global middleware. Exact System API Route and Bootstrap API Route identities are exempt; every other registered /api route is Managed and must pass Route Authorization with its registered method/pattern. A runtime with Managed routes cannot assemble without a route authorizer. The returned manifest is compared with access's deployment-owned catalog in a DB-free contract test, while runtime authorization reads the persisted catalog and current administrator and role state. System First Initialization persists only Managed definitions and gives the root role complete explicit grants; catalog baseline changes require explicit access-owned upgrade work, never startup repair or administrator CRUD.

Documentation

Overview

Package boot owns application startup wiring.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(configPath string, opts ...Option) error

Run loads configuration, assembles concrete runtime pieces, and blocks until the process receives a shutdown signal.

func UpgradeAccessAuthorization

func UpgradeAccessAuthorization(ctx context.Context, configPath string) (err error)

UpgradeAccessAuthorization runs the operator-controlled access catalog upgrade without starting the HTTP application.

Types

type App

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

App is the assembled application runtime.

func NewApp

func NewApp(cfg configs.Config, opts ...Option) (*App, error)

NewApp assembles concrete runtime pieces from config.

func (*App) Container

func (a *App) Container() do.Injector

Container returns the boot-owned dependency graph.

func (*App) Resources

func (a *App) Resources() *Resources

Resources returns configured infrastructure resources owned by the app.

func (*App) Run

func (a *App) Run(ctx context.Context) error

Run starts the assembled application runtime.

func (*App) Server

func (a *App) Server() *server.Server

Server returns the HTTP runtime so tests and boot wiring can register routes through the same interface used in production.

type Context

type Context struct {
	Config    configs.Config
	Server    *server.Server
	Router    *echo.Group
	Container do.Injector
	Resources *Resources
}

Context is the framework surface given to a module during route mounting.

type Module

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

Module is one installable business capability in the application runtime.

func BusinessModules

func BusinessModules() []Module

BusinessModules returns the business modules installed by the default runtime.

func NewModule

func NewModule(name string, opts ...ModuleOption) Module

NewModule creates a boot module with explicit providers and route mounts.

func (Module) Name

func (m Module) Name() string

Name returns the module name used in startup diagnostics.

type ModuleOption

type ModuleOption func(*Module)

ModuleOption customizes one boot module.

func Provide

func Provide[T any](provider do.Provider[T]) ModuleOption

Provide registers one do provider when the module is installed.

func Route

func Route[H any](register func(*echo.Group, H)) ModuleOption

Route mounts an HTTP route set after its handler has been resolved from do.

func Use

func Use(register func(do.Injector)) ModuleOption

Use installs a raw do package or binding as part of the module.

type Option

type Option func(*appOptions)

Option customizes application assembly.

func WithModules

func WithModules(modules ...Module) Option

WithModules installs business modules into the boot-owned dependency graph.

type Resources

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

Resources exposes framework-owned infrastructure resources to modules.

func (*Resources) Close

func (r *Resources) Close(ctx context.Context) error

Close releases every opened infrastructure resource.

func (*Resources) MongoDB

func (r *Resources) MongoDB() (*mongo.Client, bool)

MongoDB returns the configured MongoDB client when MongoDB is enabled.

func (*Resources) MySQL

func (r *Resources) MySQL() (*gorm.DB, bool)

MySQL returns the configured GORM DB when MySQL is enabled.

func (*Resources) Ready

func (r *Resources) Ready(ctx context.Context) error

Ready reports whether every enabled resource is available.

func (*Resources) Redis

func (r *Resources) Redis() (*goredis.Client, bool)

Redis returns the configured Redis client when Redis is enabled.

func (*Resources) Status

Status returns server-facing capability status records.

Jump to

Keyboard shortcuts

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