package lazyapp ¶
import "golazy.dev/lazyapp"
Variables ¶
var FilesHook, DependenciesHook, MigrationsHook, JobsHook, RoutesHook, HelpersHook, ControlPlaneHook ¶
var (
// FilesHook owns view and public filesystem contributions.
FilesHook = lazyaddon.DefineHook[FilesEvent]("golazy.dev/lazyapp/files", 1)
// DependenciesHook owns dependency service contributions.
DependenciesHook = lazyaddon.DefineHook[DependenciesEvent]("golazy.dev/lazyapp/dependencies", 1)
// MigrationsHook owns database and migration contributions.
MigrationsHook = lazyaddon.DefineHook[MigrationsEvent]("golazy.dev/lazyapp/migrations", 1)
// JobsHook owns jobs runner contributions.
JobsHook = lazyaddon.DefineHook[JobsEvent]("golazy.dev/lazyapp/jobs", 1)
// RoutesHook owns application route contributions.
RoutesHook = lazyaddon.DefineHook[RoutesEvent]("golazy.dev/lazyapp/routes", 1)
// HelpersHook owns template helper contributions.
HelpersHook = lazyaddon.DefineHook[HelpersEvent]("golazy.dev/lazyapp/helpers", 1)
// ControlPlaneHook owns operational control-plane contributions.
ControlPlaneHook = lazyaddon.DefineHook[ControlPlaneEvent]("golazy.dev/lazyapp/controlplane", 1)
)
var PublicPath ¶
var PublicPath = "app/public"
var ViewsPath ¶
var ViewsPath = "app/views"
Functions ¶
func MustSub ¶
func MustSub(fsys fs.FS, dir string) func() (fs.FS, error)
Types ¶
type App ¶
type App struct {
Name string
Addons *lazyaddon.Scope
Context context.Context
Dispatcher *lazydispatch.Dispatcher
Router *lazyroutes.Scope
Assets *lazyassets.Registry
Storages map[string]lazystorage.Storage
Files *lazyfiles.Files
Media *lazymedia.Media
Cache *lazycache.Cache
Sessions *lazysession.Manager
Migrations lazymigrate.Databases
Jobs *lazyjobs.JobRunner
Auth lazyauth.Config
OAuth *lazyoauth.Server
MCP *lazymcp.Scope
Workers *lazyworkers.Registry
PWA *lazypwa.App
ControlPlane *lazycontrolplane.ControlPlane
Dependencies *lazydeps.Scope
// contains filtered or unexported fields
}
func New ¶
func New(config Config) *App
func (app *App) ListenAndServe ¶
ListenAndServe starts the app server on ADDR, PORT, or 127.0.0.1:3000.
It installs app.Context as the server base context, so every request context includes the dependencies initialized by New. When using a custom http.Server, set BaseContext to return app.Context.
func (app *App) ListenAndServe() error
func (app *App) ServeHTTP ¶
func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
type AuthConfig ¶
AuthConfig initializes lazyauth with the dependency-initialized app context.
type AuthConfig func(context.Context) (lazyauth.Config, error)
func Auth ¶
Auth adapts a static lazyauth.Config for Config.Auth.
func Auth(config lazyauth.Config) AuthConfig
type Config ¶
type Config struct {
Name string
Addons lazyaddon.Selection
Drawer func(*lazyroutes.Scope)
Public func() (fs.FS, error)
Views func() (fs.FS, error)
Dependencies func(*lazydeps.Scope) error
Helpers Helpers
SEO func(context.Context) []lazyseo.Option
Assets []lazyassets.Source
AssetOptions []lazyassets.Option
Storages map[string]lazystorage.Storage
Files *lazyfiles.Files
Media *lazymedia.Media
Cache lazycache.Options
Robots RobotsConfig
Sitemap SitemapConfig
Sessions lazysession.Config
Migrations MigrationsConfig
Jobs JobsConfig
Auth AuthConfig
OAuth OAuthConfig
MCP MCPConfig
MCPOptions lazymcp.Options
Workers WorkersConfig
PWA lazypwa.Config
ControlPlane lazycontrolplane.Builder
Middlewares []lazydispatch.Middleware
ForceDetailErrors bool
}
type ControlPlaneEvent ¶
ControlPlaneEvent lets add-ons register owned operational endpoints, readiness checks, and development-panel descriptors. Build-tagged callback files determine which registrations exist in lazydev and production builds.
type ControlPlaneEvent struct {
Context context.Context
ControlPlane lazycontrolplane.Registrar
Addons *lazyaddon.Scope
}
type DependenciesEvent ¶
DependenciesEvent lets add-ons initialize services in the app dependency scope.
type DependenciesEvent struct {
Context context.Context
Dependencies *lazydeps.Scope
Addons *lazyaddon.Scope
}
type FilesEvent ¶
FilesEvent lets selected add-ons contribute view and public filesystem layers. lazyapp adds framework layers before this hook and application layers after it, then seals both filesystems.
type FilesEvent struct {
Context context.Context
Views *lazyfs.FS
Public *lazyfs.FS
Addons *lazyaddon.Scope
}
type Helpers ¶
type Helpers []map[string]any
type HelpersEvent ¶
HelpersEvent lets add-ons register view helpers before application-owned helpers are applied.
type HelpersEvent struct {
Context context.Context
Helpers *Helpers
Addons *lazyaddon.Scope
}
func (event *HelpersEvent) Add ¶
Add appends one helper map to the event.
func (event *HelpersEvent) Add(helpers map[string]any)
type JobsConfig ¶
JobsConfig initializes lazyjobs with the dependency-initialized app context.
type JobsConfig func(context.Context) (lazyjobs.Config, error)
func Jobs ¶
Jobs adapts a static lazyjobs.Config for Config.Jobs.
func Jobs(config lazyjobs.Config) JobsConfig
type JobsEvent ¶
JobsEvent lets an add-on enable or refine the application's jobs runner.
type JobsEvent struct {
Context context.Context
Config lazyjobs.Config
Enabled bool
Addons *lazyaddon.Scope
}
type MCPConfig ¶
MCPConfig registers application MCP modules.
type MCPConfig func(context.Context, *lazymcp.Scope) error
type MigrationsConfig ¶
MigrationsConfig initializes lazymigrate with the dependency-initialized app context.
type MigrationsConfig func(context.Context) (lazymigrate.Databases, error)
func Migrations ¶
Migrations adapts static lazymigrate databases for Config.Migrations.
func Migrations(databases lazymigrate.Databases) MigrationsConfig
type MigrationsEvent ¶
MigrationsEvent lets add-ons provide database backends and migration filesystems after dependencies are available.
type MigrationsEvent struct {
Context context.Context
Databases *lazymigrate.Databases
Catalog *lazymigrate.Catalog
Addons *lazyaddon.Scope
}
type OAuthConfig ¶
OAuthConfig initializes lazyoauth with the dependency-initialized app context.
type OAuthConfig func(context.Context) (lazyoauth.Config, error)
func OAuth ¶
OAuth adapts a static lazyoauth.Config for Config.OAuth.
func OAuth(config lazyoauth.Config) OAuthConfig
type RobotsConfig ¶
type RobotsConfig struct {
Disabled bool
Rules []RobotsRule
Sitemaps []string
Extra []string
}
type RobotsRule ¶
type RobotsRule struct {
UserAgent string
Allow []string
Disallow []string
CrawlDelay string
}
type RoutesEvent ¶
RoutesEvent lets add-ons draw routes after the application drawer.
type RoutesEvent struct {
Context context.Context
Router *lazyroutes.Scope
Addons *lazyaddon.Scope
}
type SitemapAlternate ¶
type SitemapAlternate struct {
Language string
Location string
}
type SitemapConfig ¶
type SitemapConfig struct {
Disabled bool
BaseURL string
URLs []SitemapURL
Sources []SitemapSource
}
type SitemapSource ¶
type SitemapSource interface {
SitemapURLs() ([]SitemapURL, error)
}
type SitemapSourceFunc ¶
type SitemapSourceFunc func() ([]SitemapURL, error)
func (fn SitemapSourceFunc) SitemapURLs ¶
func (fn SitemapSourceFunc) SitemapURLs() ([]SitemapURL, error)
type SitemapURL ¶
type SitemapURL struct {
Location string
LastUpdated time.Time
ChangeFreq string
Priority float64
Alternates []SitemapAlternate
}
type WorkersConfig ¶
WorkersConfig registers browser workers with the dependency-initialized app context.
type WorkersConfig func(context.Context, *lazyworkers.Registry) error
Package lazyapp composes lower-level GoLazy packages into a runnable web application.
Most applications use New at the application boundary. New creates the application context, initializes dependencies, opens configured views, creates the lazycontroller renderer, builds a lazyroutes scope, calls the route drawer, registers framework and application helpers with lazyview, initializes cache, sessions, default lazyauth, migrations, jobs, optional browser workers, PWA metadata, robots.txt, sitemap endpoints, and optional control-plane handlers, then returns one http.Handler.
Every app gets a lazyauth config in App.Auth and application context. Without Config.Auth, lazyapp uses an in-memory backend with zero users. Set LAZYAUTH_DEFAULT_PASS to create a bootstrap admin user, and set LAZYAUTH_DEFAULT_USER to change that username.
Migrations are configured through Config.Migrations. lazyapp itself does not import database drivers; applications provide lazymigrate databases with the concrete backend for each logical database. Set LAZYAPP_MIGRATE=up to run pending migrations and exit, or LAZYAPP_MIGRATE=auto to run pending migrations before jobs and normal app startup. When CONTROL_PLANE_ADDR points at a separate listener during migration mode, lazyapp starts the real control plane early so /livez is OK while /readyz reports that migrations are still running. In auto mode that listener stays active and later startup stages add their handlers to the same control plane. When the control plane shares the app listener, migrations leave it alone and ListenAndServe mounts it after migrations finish.
Public files and generated assets are registered with lazyassets and mounted as the final fallback after dynamic routes. View helpers from lazyroutes, lazyassets, lazyworkers, lazypwa, lazyforms, lazyerrors, lazyseo, lazyturbo, cache helpers, and Config.Helpers are passed to the lazyview renderer before templates are cached. Controllers usually embed lazycontroller.Base; lazyroutes binds each request to that base, and lazycontroller renders through the renderer created here.
Direct package use still makes sense when an application needs only one layer: use lazyroutes for a standalone route table, lazyassets for standalone hashed asset serving, lazyview for template rendering without controllers, or lazycontroller when a custom application shell wants GoLazy controller rendering without the rest of this composition. Use lazyapp when those pieces should behave like a conventional GoLazy application.
For embedded application files, pass subdirectories to Config with MustSub:
//go:embed public views var files embed.FS app := lazyapp.New(lazyapp.Config{ Public: lazyapp.MustSub(files, "public"), Views: lazyapp.MustSub(files, "views"), })