irmik

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 24 Imported by: 0

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

View Source
const (
	ModeSSR    = meta.ModeSSR
	ModeSSG    = meta.ModeSSG
	ModeISR    = meta.ModeISR
	ModeStatic = meta.ModeStatic
	ModeCSR    = meta.ModeCSR
)

Variables

This section is empty.

Functions

func AdaptLoader

func AdaptLoader(fn func(*Context) (any, error)) router.Loader

AdaptLoader converts an Irmik Context loader into a router.Loader.

func Wrap

func Wrap(h Handler) gin.HandlerFunc

Wrap adapts an Irmik Handler to gin.HandlerFunc.

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

func New(cfg config.Config) (*App, error)

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

func (a *App) EnableSessions() error

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

func (a *App) HTTPServer() *http.Server

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

func (a *App) Ready() bool

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

func (a *App) ReadyChecks() *health.Registry

ReadyChecks returns the readiness registry (may be empty, never nil after New).

func (*App) RegisterOptionalReadyCheck

func (a *App) RegisterOptionalReadyCheck(name string, fn health.CheckFunc)

RegisterOptionalReadyCheck adds a probe reported on /ready but ignored for readiness.

func (*App) RegisterReadyCheck

func (a *App) RegisterReadyCheck(name string, fn health.CheckFunc)

RegisterReadyCheck adds a required dependency probe for /ready. /health remains liveness-only. Example:

app.RegisterReadyCheck("db", health.PingDB(db))

func (*App) RemountPages

func (a *App) RemountPages() error

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

func (a *App) Run(ctx context.Context) error

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) Use

func (a *App) Use(p plugin.Plugin) error

Use registers a plugin on the app registry.

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

func (a *App) UseRequestLogWith(logger *slog.Logger)

UseRequestLogWith is UseRequestLog with an explicit logger.

type Context

type Context struct {
	*gin.Context
}

Context is a thin request wrapper around gin.Context for framework handlers.

func FromGin

func FromGin(c *gin.Context) *Context

FromGin wraps a gin.Context.

func (*Context) MustUser

func (c *Context) MustUser() auth.User

MustUser returns the authenticated user, or panics if none is in context.

func (*Context) Param

func (c *Context) Param(key string) string

Param is a convenience alias for gin.Context.Param.

func (*Context) Query

func (c *Context) Query(key string) string

Query is a convenience alias for gin.Context.Query.

func (*Context) RequestID

func (c *Context) RequestID() string

RequestID returns the request id set by middleware (if any).

func (*Context) Session

func (c *Context) Session() *session.Session

Session returns the cookie session when session middleware is installed.

func (*Context) User

func (c *Context) User() (auth.User, bool)

User returns the authenticated user injected by auth middleware, if any.

type Handler

type Handler func(*Context)

Handler is the Irmik request handler signature.

type Mode

type Mode = meta.Mode

Mode selects how a route is rendered.

type MountOptions

type MountOptions struct {
	Loaders map[string]router.Loader
	// Funcs are extra template helpers (SEO, etc.).
	Funcs template.FuncMap
	// SkipIslands disables automatic island.FromConfig wiring.
	SkipIslands bool
}

MountOptions configures file-based page mounting.

type PageMeta

type PageMeta = meta.PageMeta

PageMeta configures route-level rendering behavior.

func DefaultMeta

func DefaultMeta() PageMeta

DefaultMeta returns SSR with sitemap enabled.

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.
db
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.

Jump to

Keyboard shortcuts

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