framework

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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

func PrintCheck(w io.Writer, findings []Finding, asJSON bool) int

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

func PrintRoutes(w io.Writer, infos []RouteInfo, asJSON bool)

PrintRoutes renders the route table (human) or JSON to w. Used by the `monobin routes` subcommand and reusable by scaffolded projects.

func RoutePattern

func RoutePattern(r *http.Request) string

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

func New(embedded embed.FS, dev bool) (*App, error)

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

func (a *App) BuildStatic(outDir string) error

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

func (a *App) Check() []Finding

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

func (a *App) Handler() http.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

func (a *App) Loader(pattern string, fn Loader)

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

func (a *App) Meta(pattern string, kv map[string]string)

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

func (a *App) NoStatic(patterns ...string)

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

func (a *App) Redirect(from, to string)

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

func (a *App) Robots(baseURL string) []byte

Robots renders a robots.txt that allows everything and points at the sitemap.

func (*App) RouteInfo

func (a *App) RouteInfo() []RouteInfo

RouteInfo returns every route with its flags, sorted as matched (static first).

func (*App) Serve

func (a *App) Serve(addr string) error

Serve starts the HTTP server: matched routes -> SSR, /assets/ -> embedded build.

func (*App) Sitemap added in v0.3.0

func (a *App) Sitemap(baseURL string) ([]byte, error)

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

type Ctx struct {
	Request *http.Request
	Params  map[string]string
}

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 Loader

type Loader func(c *Ctx) (any, error)

Loader runs server-side before render; its return value is the template's .Data.

type Middleware

type Middleware func(http.Handler) http.Handler

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

type StaticPaths func() ([]map[string]string, error)

StaticPaths enumerates the concrete param sets to pre-render for a dynamic route at build time (like Next's getStaticPaths / Astro's getStaticPaths).

Jump to

Keyboard shortcuts

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