golazy.dev
–
golazy.dev
/
lazyapp
Index
|
Files
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
Cache *lazycache.Cache
Sessions *lazysession.Manager
Jobs *lazyjobs.JobRunner
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 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
Cache lazycache.Options
Robots RobotsConfig
Sitemap SitemapConfig
Sessions lazysession.Config
Jobs JobsConfig
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 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
}
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, jobs, robots.txt, sitemap endpoints, and optional control-plane handlers, then returns one http.Handler.
Public files and generated assets are registered with lazyassets and mounted as the final fallback after dynamic routes. View helpers from lazyroutes, lazyassets, 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"), })