Documentation
¶
Index ¶
- Constants
- Variables
- func PrintCheck(w io.Writer, findings []Finding, asJSON bool) int
- func PrintRoutes(w io.Writer, infos []RouteInfo, asJSON bool)
- func RoutePattern(r *http.Request) string
- type App
- func (a *App) BuildStatic(outDir string) error
- func (a *App) Check() []Finding
- func (a *App) Handler() http.Handler
- func (a *App) Loader(pattern string, fn Loader)
- func (a *App) Meta(pattern string, kv map[string]string)
- func (a *App) NoStatic(patterns ...string)
- func (a *App) Redirect(from, to string)
- func (a *App) Robots(baseURL string) []byte
- func (a *App) RouteInfo() []RouteInfo
- func (a *App) Serve(addr string) error
- func (a *App) Sitemap(baseURL string) ([]byte, error)
- func (a *App) StaticPaths(pattern string, fn StaticPaths)
- func (a *App) Use(mw ...Middleware)
- type Ctx
- type Finding
- type Loader
- type Middleware
- type RouteInfo
- type StaticPaths
Constants ¶
const Version = "v0.3.0"
Version is the framework release. `monobin new` pins generated projects to it so a scaffold builds reproducibly instead of floating on `latest`.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound lets a loader signal a 404 (e.g. unknown :slug).
Functions ¶
func PrintCheck ¶ added in v0.3.0
PrintCheck renders findings (human or JSON) to w and returns the process exit code (1 if any error-level finding, else 0).
func PrintRoutes ¶ added in v0.3.0
PrintRoutes renders the route table (human) or JSON to w. Used by the `monobin routes` subcommand and reusable by scaffolded projects.
func RoutePattern ¶
RoutePattern returns the matched route pattern (e.g. "/blog/:slug") for the current request, or "" if nothing matched. Middleware uses it to gate by pattern/prefix without re-parsing the URL.
Types ¶
type App ¶
type App struct {
Dev bool
// SiteURL is the absolute origin (e.g. https://example.com) used for
// sitemap.xml / robots.txt. Empty on serve falls back to the request host.
SiteURL string
// contains filtered or unexported fields
}
func New ¶
New builds an App. Dev reads app/ from disk (live reload, no recompile); prod uses the embedded copy baked into the binary.
func (*App) BuildStatic ¶
BuildStatic renders every route to static HTML under outDir. Dynamic routes are expanded via their registered StaticPaths. Output is a plain folder you can serve from anywhere (Caddy file_server, R2, a CDN).
func (*App) Check ¶
Check statically validates the app: templates parse, dynamic routes have StaticPaths (warn), islands referenced in templates are registered in entry.js, and loader/StaticPaths keys map to real routes.
func (*App) Handler ¶
Handler builds the full HTTP handler (assets, dev live-reload, and the middleware-wrapped route renderer). Exposed so tests and embedders can drive the app without binding a port.
func (*App) Loader ¶ added in v0.3.0
Loader registers a server-side loader keyed by route pattern; its return value becomes the template's .Data. A loader returning ErrNotFound yields a 404 at runtime and is skipped by `monobin build`. This is where Postgres/Redis/API calls go — server-only, SEO-safe.
func (*App) Meta ¶ added in v0.3.0
Meta attaches arbitrary string metadata to a route pattern. It is exposed to the route's template as .Meta and used as sitemap hints (changefreq, priority).
func (*App) NoStatic ¶
NoStatic marks route patterns the static builder must not pre-render (e.g. auth-gated or personalized SSR-only pages). They still render under `serve`.
func (*App) Redirect ¶ added in v0.3.0
Redirect registers a permanent (301) redirect from one path to another. It is applied before route matching on the serve path, and emitted to a _redirects file (Netlify/Cloudflare format) by `monobin build`.
func (*App) Robots ¶ added in v0.3.0
Robots renders a robots.txt that allows everything and points at the sitemap.
func (*App) RouteInfo ¶
RouteInfo returns every route with its flags, sorted as matched (static first).
func (*App) Serve ¶
Serve starts the HTTP server: matched routes -> SSR, /assets/ -> embedded build.
func (*App) Sitemap ¶ added in v0.3.0
Sitemap renders sitemap.xml for every build-visible route (static routes plus dynamic routes expanded through their StaticPaths), with baseURL prepended. NoStatic routes are omitted, matching what `monobin build` emits.
func (*App) StaticPaths ¶ added in v0.3.0
func (a *App) StaticPaths(pattern string, fn StaticPaths)
StaticPaths registers the concrete param sets to pre-render for a dynamic route at build time (like Next/Astro getStaticPaths).
func (*App) Use ¶
func (a *App) Use(mw ...Middleware)
Use appends middleware to the chain applied around the route handler on the serve path. They run outermost-first in registration order: the first Use'd middleware sees the request first and the response last. Middleware never runs during `monobin build` (SSG renders routes directly).
type Ctx ¶
Ctx is passed to every loader. Params holds dynamic route segments, e.g. for /blog/:slug, Params["slug"] is the matched value.
type Finding ¶
type Finding struct {
Level string `json:"level"`
Where string `json:"where"`
Message string `json:"message"`
Fix string `json:"fix"`
}
Finding is one result from Check. Level is "error" (fails `monobin check`) or "warn" (reported, non-fatal).
type Middleware ¶
Middleware wraps an http.Handler. This is the single extension hook the core owns; auth, logging, security headers, and rate limiting are all built on it in user-land — the framework ships none of them itself.
type RouteInfo ¶
type RouteInfo struct {
Pattern string `json:"pattern"`
Template string `json:"template"`
Dynamic bool `json:"dynamic"`
HasLoader bool `json:"hasLoader"`
HasStaticPaths bool `json:"hasStaticPaths"`
}
RouteInfo is the machine-readable shape of one route (for `monobin routes`).
type StaticPaths ¶
StaticPaths enumerates the concrete param sets to pre-render for a dynamic route at build time (like Next's getStaticPaths / Astro's getStaticPaths).