app

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package app wires the HTTP server, module registration, and lifecycle management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

App owns the HTTP server, registered modules, and bootstrapped dependencies.

func New

func New(cfg *config.Config, log *logx.Logger, modules []Module) (*App, error)

New builds an App instance, wires dependencies, and registers all modules.

Usage:

a, err := app.New(cfg, logger, modules.All())

Notes: - DependencyBinder modules receive initialized dependencies before Register - Any registration failure aborts startup and closes allocated resources

func (*App) Run

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

Run starts the HTTP server and blocks until shutdown or fatal server error.

Side effects: - Listens on cfg.HTTP.Addr - Closes dependencies during shutdown - Uses cfg.HTTP.ShutdownTimeout for graceful stop

type Dependencies

type Dependencies struct {
	// Postgres is the optional pgx pool initialized from config.
	Postgres *pgxpool.Pool
	// Redis is the optional Redis client used by auth/cache/ratelimit.
	Redis *redis.Client
	// Readiness aggregates health checks for readiness responses.
	Readiness *readiness.Service
	// Metrics is the Prometheus instrumentation service.
	Metrics *metrics.Service
	// Tracing is the OpenTelemetry lifecycle service.
	Tracing *tracing.Service
	// AuthEngine is the optional goAuth engine.
	AuthEngine *goauth.Engine
	// AuthMode is the normalized auth mode used by auth policies.
	AuthMode auth.Mode
	// RateLimit is the resolved rate-limit config snapshot.
	RateLimit config.RateLimitConfig
	// Cache is the resolved cache config snapshot.
	Cache config.CacheConfig
	// Limiter is the optional route rate limiter.
	Limiter ratelimit.Limiter
	// CacheMgr is the optional response cache manager.
	CacheMgr *cache.Manager
	// contains filtered or unexported fields
}

Dependencies stores initialized process-level services shared with modules.

type DependencyBinder

type DependencyBinder interface {
	BindDependencies(*Dependencies)
}

DependencyBinder allows modules to receive initialized Dependencies.

type Module

type Module interface {
	Name() string
	Register(r httpx.Router) error
}

Module is the runtime contract every API module must satisfy.

A module declares a stable name and registers routes on the shared router.

Jump to

Keyboard shortcuts

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