Documentation
¶
Overview ¶
Package irmik is a Gin meta-framework for server-rendered pages, sessions, and an opt-in catalog (auth, admin, upload, queues, images, and more).
In development, New injects a small overlay (badge, errors, live reload via irmik dev). Those routes are not mounted in production.
Index ¶
- Constants
- func AdaptLoader(fn func(*Context) (any, error)) router.Loader
- func Wrap(h Handler) gin.HandlerFunc
- type App
- func (a *App) EnableAuth() *auth.Authenticator
- func (a *App) EnableRateLimit(cfg middleware.RateLimitConfig)
- func (a *App) EnableSecureDefaults()
- func (a *App) EnableSecureHeaders(cfg middleware.SecureHeadersConfig)
- func (a *App) EnableSessions() error
- func (a *App) HTTPServer() *http.Server
- func (a *App) MountPages(opts MountOptions) error
- func (a *App) Ready() bool
- func (a *App) ReadyChecks() *health.Registry
- func (a *App) RegisterOptionalReadyCheck(name string, fn health.CheckFunc)
- func (a *App) RegisterReadyCheck(name string, fn health.CheckFunc)
- func (a *App) RemountPages() error
- func (a *App) Run(ctx context.Context) error
- func (a *App) Use(p plugin.Plugin) error
- func (a *App) UseRequestLog()
- func (a *App) UseRequestLogWith(logger *slog.Logger)
- type Context
- type Handler
- type Mode
- type MountOptions
- type PageMeta
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func AdaptLoader ¶
AdaptLoader converts an Irmik Context loader into a router.Loader.
Types ¶
type App ¶
type App struct {
Config config.Config
Engine *gin.Engine
Cache cache.Store
Plugins *plugin.Registry
Router *router.Router
Renderer *render.Engine
Islands *island.Manager
// Sessions is optional cookie session manager (EnableSessions).
Sessions *session.Manager
// Auth is optional authenticator (EnableAuth); JWT + session helpers.
Auth *auth.Authenticator
// Devtools is the development overlay (nil outside development).
Devtools *devtools.Dev
// contains filtered or unexported fields
}
App is the Irmik application root: Gin engine, cache, and plugin registry.
func New ¶
New constructs an App from cfg: Gin engine, default middleware, health routes, cache store, and an empty plugin registry.
func (*App) EnableAuth ¶
func (a *App) EnableAuth() *auth.Authenticator
EnableAuth constructs an auth.Authenticator from cfg.Auth. Refresh tokens use a process-local MemoryRefreshStore by default (not multi-replica). Does not mount middleware; call Auth.InjectSessionUser / MiddlewareJWT as needed.
func (*App) EnableRateLimit ¶
func (a *App) EnableRateLimit(cfg middleware.RateLimitConfig)
EnableRateLimit mounts an in-memory token-bucket limiter (per ClientIP by default). For login/auth routes, prefer middleware.LoginRateLimit on those routes instead of (or in addition to) a loose global limit.
func (*App) EnableSecureDefaults ¶
func (a *App) EnableSecureDefaults()
EnableSecureDefaults turns on admin-oriented protections beyond baseline headers: global in-memory rate limiting. Pair with csrf.Middleware for browser form/admin UIs. Headers are already applied in New; production also gets HSTS.
func (*App) EnableSecureHeaders ¶
func (a *App) EnableSecureHeaders(cfg middleware.SecureHeadersConfig)
EnableSecureHeaders replaces the security-header config mounted in New. It does not stack another middleware: Skip flags and custom CSP/frame values take effect, and stale defaults from New are not kept.
func (*App) EnableSessions ¶
EnableSessions constructs a session.Manager from cfg.Session and mounts its middleware on the Gin engine. Safe to call once after New.
func (*App) HTTPServer ¶
HTTPServer returns the underlying http.Server after Run has started it.
func (*App) MountPages ¶
func (a *App) MountPages(opts MountOptions) error
MountPages creates the renderer (if needed), discovers app/ routes, and binds Gin handlers.
func (*App) Ready ¶
Ready reports whether the app has finished starting and required dependency checks pass. Used by callers; /ready also runs Checks via HealthWith.
func (*App) ReadyChecks ¶
ReadyChecks returns the readiness registry (may be empty, never nil after New).
func (*App) RegisterOptionalReadyCheck ¶
RegisterOptionalReadyCheck adds a probe reported on /ready but ignored for readiness.
func (*App) RegisterReadyCheck ¶
RegisterReadyCheck adds a required dependency probe for /ready. /health remains liveness-only. Example:
app.RegisterReadyCheck("db", health.PingDB(db))
func (*App) RemountPages ¶
RemountPages reloads templates and rediscovers routes in memory. Gin handlers are not re-bound (duplicate registration); new routes need a process restart.
func (*App) Run ¶
Run listens on cfg.Server address until ctx is cancelled (or SIGINT/SIGTERM), then shuts down gracefully using Server.ShutdownTimeout. Plugin hooks: before_start → after_start → (serve) → before_stop → after_stop.
func (*App) UseRequestLog ¶
func (a *App) UseRequestLog()
UseRequestLog mounts structured slog request logging (method, path, status, latency, request-id). Opt-in; uses slog.Default() when logger is nil.
func (*App) UseRequestLogWith ¶
UseRequestLogWith is UseRequestLog with an explicit logger.
type Context ¶
Context is a thin request wrapper around gin.Context for framework handlers.
func (*Context) MustUser ¶
MustUser returns the authenticated user, or panics if none is in context.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package admin provides thin HTMX CRUD conventions for admin UIs: session flash ↔ HX-Trigger helpers, pagination re-export patterns, and embeddable table/form/delete-confirm template snippets.
|
Package admin provides thin HTMX CRUD conventions for admin UIs: session flash ↔ HX-Trigger helpers, pagination re-export patterns, and embeddable table/form/delete-confirm template snippets. |
|
Package api provides thin REST helpers: JSON responses, a standard error envelope, and an /api/v1 group mount.
|
Package api provides thin REST helpers: JSON responses, a standard error envelope, and an /api/v1 group mount. |
|
Package audit provides a simple audit-log interface with slog and memory sinks.
|
Package audit provides a simple audit-log interface with slog and memory sinks. |
|
Package auth provides session login helpers, JWT access tokens, password hashing, OAuth provider stubs, and Gin middleware.
|
Package auth provides session login helpers, JWT access tokens, password hashing, OAuth provider stubs, and Gin middleware. |
|
redisx
Package redisx registers a Redis-backed cache.Store.
|
Package redisx registers a Redis-backed cache.Store. |
|
Package compress provides Gin middleware for response compression.
|
Package compress provides Gin middleware for response compression. |
|
brotlix
Package brotlix provides optional Brotli Gin middleware.
|
Package brotlix provides optional Brotli Gin middleware. |
|
Package content loads Markdown collections with YAML/TOML/JSON frontmatter.
|
Package content loads Markdown collections with YAML/TOML/JSON frontmatter. |
|
Package cors provides a lean CORS middleware for Gin (no heavy dependency).
|
Package cors provides a lean CORS middleware for Gin (no heavy dependency). |
|
Package csrf provides CSRF token generation and Gin middleware for cookie/session-backed forms.
|
Package csrf provides CSRF token generation and Gin middleware for cookie/session-backed forms. |
|
Package db opens and wraps database/sql connections for Irmik apps.
|
Package db opens and wraps database/sql connections for Irmik apps. |
|
mysql
Package mysql registers the MySQL database/sql driver.
|
Package mysql registers the MySQL database/sql driver. |
|
postgres
Package postgres registers the pgx database/sql driver for PostgreSQL.
|
Package postgres registers the pgx database/sql driver for PostgreSQL. |
|
sqlite
Package sqlite registers the pure-Go SQLite driver (modernc.org/sqlite).
|
Package sqlite registers the pure-Go SQLite driver (modernc.org/sqlite). |
|
Package devtools injects a development-only overlay (badge, errors, live reload).
|
Package devtools injects a development-only overlay (badge, errors, live reload). |
|
Package forms provides form parse/validate glue and CSRF field HTML helpers.
|
Package forms provides form parse/validate glue and CSRF field HTML helpers. |
|
Package fsutil provides small filesystem helpers shared by build, cache, and tooling.
|
Package fsutil provides small filesystem helpers shared by build, cache, and tooling. |
|
Package health provides named readiness dependency checks (DB, Redis, custom).
|
Package health provides named readiness dependency checks (DB, Redis, custom). |
|
Package htmx — quick reference for admin handlers:
|
Package htmx — quick reference for admin handlers: |
|
Package imagex provides image decode/resize/encode helpers and an opt-in responsive-image pipeline for SSR pages and uploads.
|
Package imagex provides image decode/resize/encode helpers and an opt-in responsive-image pipeline for SSR pages and uploads. |
|
Package island wires React/Vite islands into html/template pages.
|
Package island wires React/Vite islands into html/template pages. |
|
Package mail defines a small email Sender interface with a net/smtp implementation.
|
Package mail defines a small email Sender interface with a net/smtp implementation. |
|
Package meta holds page rendering mode and metadata shared by router and app.
|
Package meta holds page rendering mode and metadata shared by router and app. |
|
Package migrate runs versioned SQL migrations using golang-migrate.
|
Package migrate runs versioned SQL migrations using golang-migrate. |
|
Package observe provides structured slog helpers for Irmik apps.
|
Package observe provides structured slog helpers for Irmik apps. |
|
Package openapi provides a lightweight OpenAPI 3 document builder and Gin serve helper.
|
Package openapi provides a lightweight OpenAPI 3 document builder and Gin serve helper. |
|
Package paginate parses list query params (page, per_page, sort, order, q) with clamped limits and SQL-friendly Offset/Limit plus whitelist OrderBy.
|
Package paginate parses list query params (page, per_page, sort, order, q) with clamped limits and SQL-friendly Offset/Limit plus whitelist OrderBy. |
|
Package proxy provides a small reverse-proxy helper for Gin using httputil.
|
Package proxy provides a small reverse-proxy helper for Gin using httputil. |
|
Package queue provides a small job-queue interface and an in-memory implementation with a worker Run loop.
|
Package queue provides a small job-queue interface and an in-memory implementation with a worker Run loop. |
|
Package rbac provides a simple role/permission registry and Gin middleware.
|
Package rbac provides a simple role/permission registry and Gin middleware. |
|
store
Package store provides opt-in persistence for irmik/rbac.
|
Package store provides opt-in persistence for irmik/rbac. |
|
Package render provides an html/template engine with layouts, partials, and an island helper stub for the Vite/React island package to replace.
|
Package render provides an html/template engine with layouts, partials, and an island helper stub for the Vite/React island package to replace. |
|
Package router discovers file-based app/ routes and binds them to Gin with SSR / SSG / ISR / Static / CSR handlers.
|
Package router discovers file-based app/ routes and binds them to Gin with SSR / SSG / ISR / Static / CSR handlers. |
|
Package scheduler provides an opt-in job registry with fixed intervals and timezone-aware cron (robfig/cron/v3).
|
Package scheduler provides an opt-in job registry with fixed intervals and timezone-aware cron (robfig/cron/v3). |
|
Package secrets provides a small secret Provider interface with env and file backends.
|
Package secrets provides a small secret Provider interface with env and file backends. |
|
Package seo builds page meta tags, JSON-LD, sitemaps, and robots.txt.
|
Package seo builds page meta tags, JSON-LD, sitemaps, and robots.txt. |
|
redisx
Package redisx registers a Redis-backed session.Store.
|
Package redisx registers a Redis-backed session.Store. |
|
Package slug converts titles and paths into URL-safe slugs.
|
Package slug converts titles and paths into URL-safe slugs. |
|
Package sse provides Server-Sent Events helpers for Gin handlers.
|
Package sse provides Server-Sent Events helpers for Gin handlers. |
|
Package storage defines a small object-storage interface with a local filesystem implementation.
|
Package storage defines a small object-storage interface with a local filesystem implementation. |
|
Package testkit provides HTTP test helpers for Gin and Irmik-style apps.
|
Package testkit provides HTTP test helpers for Gin and Irmik-style apps. |
|
Package tmplfunc provides shared html/template helpers for Irmik render engines.
|
Package tmplfunc provides shared html/template helpers for Irmik render engines. |
|
Package upload provides multipart file upload helpers with size and MIME limits.
|
Package upload provides multipart file upload helpers with size and MIME limits. |
|
Package validate provides request/struct validation helpers for Gin, built on go-playground/validator.
|
Package validate provides request/struct validation helpers for Gin, built on go-playground/validator. |
|
Package ws provides WebSocket upgrade helpers and a room-aware Hub for Gin.
|
Package ws provides WebSocket upgrade helpers and a room-aware Hub for Gin. |