package lazyapp ¶
import "golazy.dev/lazyapp"
Variables ¶
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
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
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
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 Helpers ¶
type 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 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 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 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, migrations, jobs, optional browser workers, PWA metadata, robots.txt, sitemap endpoints, and optional control-plane handlers, then returns one http.Handler.
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, 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"), })