boot

package
v0.0.0-...-1f1dc5f Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 50 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 reader, recorder, and login-session interfaces it needs, while boot passes the concrete identity/access/auth MySQL stores and bridges login records into the audit usecase. Access also receives a small identity reader so role delegation can use the current administrator’s assigned roles and active role without importing the identity adapter directly. Settings receives a version-catalog bridge here so version bundles can export/import access-owned menus and APIs without making settings import the access adapter. 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: server receives only an opaque-token authenticator and does not import auth storage. Internal-error recording is wired through a small recorder interface, with boot bridging it to the audit usecase. System First Initialization is also wired here: boot lets the setup module own installation state and coordinates one transaction across setup, access, identity, and settings stores to create the root authorization baseline, first administrator, initial settings, and completion marker. Business modules should not import each other’s adapters directly.

Authorization uses Casbin RBAC inside the auth usecase. Boot wires auth to identity for users, access for roles, data-role visibility, gin-vue-admin-style menus, menu buttons, and managed API routes, audit for login records, and auth-owned Login Session storage. Boot also installs the API route authorization middleware on the /api group before business modules are mounted, so every later private route is checked once by Echo's registered method/path pattern. The auth module builds a Casbin {subject, object, action} policy snapshot for permission-token views and checks the active role's API ids for route authorization; ordinary roles must hold the matching API id, while public setup/login bootstrap routes are skipped before the API catalog exists. During System First Initialization, access creates the root role with every initial menu id, button id, API id, and existing role id for data authority, including API Token, current-user profile, system parameter, login-session logout routes, setup-state routes, system-error resolution, and version import/export routes. Future RBAC baseline changes should be explicit access-owned upgrade work, not startup repair.

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.

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) Shutdown

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

Shutdown releases every opened infrastructure resource.

func (*Resources) Status

func (r *Resources) Status(ctx context.Context) []server.CapabilityStatus

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