inertia

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 19 Imported by: 1

README

Lemmego Inertia

The inertia plugin for the Lemmego framework.

Documentation

Index

Constants

View Source
const InertiaBuildPath = "/public/build/"
View Source
const InertiaManifestPath = "./public/build/manifest.json"
View Source
const InertiaRootTemplatePath = "resources/views/root.html"
View Source
const ViteHotPath = "./public/hot"

Variables

This section is empty.

Functions

func AddFlash added in v0.1.2

func AddFlash(ctx context.Context, flash Flash) context.Context

AddFlash appends flash data to the context.

func AddValidationErrors added in v0.1.2

func AddValidationErrors(ctx context.Context, errors ValidationErrors) context.Context

AddValidationErrors appends validation errors to the context.

func Back added in v0.1.2

func Back(c app.Context)

Back redirects the user to the previous URL via the registered Inertia instance.

func ClearHistory added in v0.1.2

func ClearHistory(ctx context.Context) context.Context

ClearHistory marks that history should be cleared on the next request.

func GetProps added in v0.1.2

func GetProps(ctx context.Context) map[string]any

GetProps retrieves props from the context.

func GetTemplateData added in v0.1.2

func GetTemplateData(ctx context.Context) map[string]any

GetTemplateData retrieves template data from the context.

func IsInertiaRequest added in v0.1.2

func IsInertiaRequest(r *http.Request) bool

IsInertiaRequest returns true if the request was made by the Inertia client.

func Location added in v0.1.2

func Location(c app.Context, url string, status ...int)

Location performs an external redirect via the registered Inertia instance.

func Redirect added in v0.1.2

func Redirect(c app.Context, url string)

Redirect performs a server-side redirect via the registered Inertia instance.

func Respond

func Respond(c app.Context, filePath string, props map[string]any) error

Respond renders an Inertia page response. Validation errors from the session are automatically merged into props.

func SetEncryptHistory added in v0.1.2

func SetEncryptHistory(ctx context.Context, encrypt ...bool) context.Context

SetEncryptHistory enables or disables history encryption for the next request.

func SetFlash added in v0.1.2

func SetFlash(ctx context.Context, flash Flash) context.Context

SetFlash stores flash data on the context for the next Inertia request.

func SetFlashValue added in v0.1.2

func SetFlashValue(ctx context.Context, key string, val any) context.Context

SetFlashValue stores a single flash value on the context.

func SetProp added in v0.1.2

func SetProp(ctx context.Context, key string, val any) context.Context

SetProp stores a single prop value on the context.

func SetProps added in v0.1.2

func SetProps(ctx context.Context, props map[string]any) context.Context

SetProps stores props on the context. Props set this way are merged into every page rendered during the request.

func SetTemplateData added in v0.1.2

func SetTemplateData(ctx context.Context, data map[string]any) context.Context

SetTemplateData stores template data on the context. Values set this way are available in the root template.

func SetTemplateDatum added in v0.1.2

func SetTemplateDatum(ctx context.Context, key string, val any) context.Context

SetTemplateDatum stores a single template datum on the context.

func SetValidationError added in v0.1.2

func SetValidationError(ctx context.Context, key string, msg string) context.Context

SetValidationError stores a single validation error message on the context.

func SetValidationErrors added in v0.1.2

func SetValidationErrors(ctx context.Context, errors ValidationErrors) context.Context

SetValidationErrors stores validation errors on the context for the next Inertia request. Typically called before a Redirect.

func Vite

func Vite(manifestPath, buildDir string) func(p string) (string, error)

Vite returns a template function that resolves Vite asset paths from a manifest file. Used when not leveraging gonertia's built-in Vite support.

Types

type AlwaysProp added in v0.1.2

type AlwaysProp struct {
	Value any
}

AlwaysProp is a property always included, even during partial reloads.

func Always added in v0.1.2

func Always(value any) AlwaysProp

Always creates an always-evaluated prop value.

func (AlwaysProp) Prop added in v0.1.2

func (p AlwaysProp) Prop() any

type Assertable added in v0.1.2

type Assertable struct {
	Body *bytes.Buffer
	// contains filtered or unexported fields
}

Assertable wraps an Inertia page response with assertion helpers for testing.

func AssertFromBytes added in v0.1.2

func AssertFromBytes(t T, body []byte) Assertable

AssertFromBytes parses an Inertia response bytes and returns an Assertable.

func AssertFromReader added in v0.1.2

func AssertFromReader(t T, body io.Reader) Assertable

AssertFromReader parses an Inertia response body and returns an Assertable.

func AssertFromString added in v0.1.2

func AssertFromString(t T, body string) Assertable

AssertFromString parses an Inertia response string and returns an Assertable.

func (Assertable) AssertClearHistory added in v0.1.2

func (a Assertable) AssertClearHistory(want bool)

AssertClearHistory verifies the clear history flag.

func (Assertable) AssertComponent added in v0.1.2

func (a Assertable) AssertComponent(want string)

AssertComponent verifies that the response component matches want.

func (Assertable) AssertDeferredProps added in v0.1.2

func (a Assertable) AssertDeferredProps(want map[string][]string)

AssertDeferredProps verifies the deferred props map.

func (Assertable) AssertEncryptHistory added in v0.1.2

func (a Assertable) AssertEncryptHistory(want bool)

AssertEncryptHistory verifies the encrypt history flag.

func (Assertable) AssertMergeProps added in v0.1.2

func (a Assertable) AssertMergeProps(want []string)

AssertMergeProps verifies the merge props list.

func (Assertable) AssertProps added in v0.1.2

func (a Assertable) AssertProps(want map[string]any)

AssertProps verifies that the response props match want.

func (Assertable) AssertURL added in v0.1.2

func (a Assertable) AssertURL(want string)

AssertURL verifies that the response URL matches want.

func (Assertable) AssertVersion added in v0.1.2

func (a Assertable) AssertVersion(want string)

AssertVersion verifies that the response version matches want.

func (Assertable) ClearHistory added in v0.1.2

func (a Assertable) ClearHistory() bool

ClearHistory returns the clear history flag.

func (Assertable) Component added in v0.1.2

func (a Assertable) Component() string

Component returns the page component name.

func (Assertable) DeepMergeProps added in v0.1.2

func (a Assertable) DeepMergeProps() []string

DeepMergeProps returns the deep merge props list.

func (Assertable) DeferredProps added in v0.1.2

func (a Assertable) DeferredProps() map[string][]string

DeferredProps returns the deferred props map.

func (Assertable) EncryptHistory added in v0.1.2

func (a Assertable) EncryptHistory() bool

EncryptHistory returns the encrypt history flag.

func (Assertable) MatchPropsOn added in v0.1.2

func (a Assertable) MatchPropsOn() []string

MatchPropsOn returns the match props on list.

func (Assertable) MergeProps added in v0.1.2

func (a Assertable) MergeProps() []string

MergeProps returns the merge props list.

func (Assertable) PrependProps added in v0.1.2

func (a Assertable) PrependProps() []string

PrependProps returns the prepend props list.

func (Assertable) Props added in v0.1.2

func (a Assertable) Props() map[string]any

Props returns the page props.

func (Assertable) ScrollProps added in v0.1.2

func (a Assertable) ScrollProps() map[string]map[string]any

ScrollProps returns the scroll props metadata as a generic map.

func (Assertable) URL added in v0.1.2

func (a Assertable) URL() string

URL returns the request URL.

func (Assertable) Version added in v0.1.2

func (a Assertable) Version() string

Version returns the asset version.

type Config added in v0.1.2

type Config struct {
	Version         string
	VersionFromFile string
	VersionFS       any // io/fs.FS
	VersionFSPath   string
	SSREnabled      bool
	SSRURL          string
	SSRHTTPClient   any // *http.Client
	FlashProvider   FlashProvider
	ContainerID     string
	EncryptHistory  bool
	JSONMarshaller  JSONMarshaller
	Logger          Logger
	ViteEnabled     bool
	ViteCfg         *ViteConfig
}

Config captures all user-facing inertia options before being translated into gonertia options internally.

type DeferProp added in v0.1.2

type DeferProp struct {
	Value any
	Group string
	// contains filtered or unexported fields
}

DeferProp is a property evaluated after the page has loaded. https://inertiajs.com/deferred-props

func Defer added in v0.1.2

func Defer(value any, group ...string) DeferProp

Defer creates a deferred prop value that loads after the initial page render.

func (DeferProp) Merge added in v0.1.2

func (p DeferProp) Merge() DeferProp

Merge makes the deferred prop merge instead of overwrite on subsequent loads.

func (DeferProp) Prop added in v0.1.2

func (p DeferProp) Prop() any

type Flash

type Flash map[string]any

Flash contains arbitrary one-time data exposed as page.flash.

func GetFlash added in v0.1.2

func GetFlash(ctx context.Context) Flash

GetFlash retrieves flash data from the context.

type FlashProvider added in v0.1.2

type FlashProvider interface {
	FlashErrors(ctx context.Context, errors ValidationErrors) error
	GetErrors(ctx context.Context) (ValidationErrors, error)
	Flash(ctx context.Context, flash Flash) error
	GetFlash(ctx context.Context) (Flash, error)
	ShouldClearHistory(ctx context.Context) (bool, error)
	FlashClearHistory(ctx context.Context) error
}

FlashProvider defines the contract for persisting validation errors and flash data across redirects. Implementations store values keyed by session ID.

func NewFlash

func NewFlash() FlashProvider

NewFlash creates a new in-memory flash provider.

type Inertia

type Inertia struct {
	// contains filtered or unexported fields
}

Inertia wraps gonertia.Inertia so that the rest of the framework never imports gonertia directly.

func Get

func Get(a app.App) *Inertia

Get retrieves the registered Inertia instance from the app container.

func NewInertia

func NewInertia(a app.App, rootTemplatePath string, opts ...Option) *Inertia

NewInertia creates a new Inertia instance. User-supplied Options are collected into a Config, then translated into gonertia options internally.

func (*Inertia) Back

func (i *Inertia) Back(c app.Context)

Back redirects the user to the previous URL.

func (*Inertia) Location added in v0.1.2

func (i *Inertia) Location(c app.Context, url string, status ...int)

Location performs an external redirect. For Inertia requests it sends a 409 response with an X-Inertia-Location header; otherwise a standard HTTP redirect.

func (*Inertia) Middleware added in v0.1.2

func (i *Inertia) Middleware(next http.Handler) http.Handler

Middleware returns an HTTP middleware that handles Inertia request detection, version checks, flash data resolution, and response wrapping.

func (*Inertia) Redirect

func (i *Inertia) Redirect(c app.Context, url string)

Redirect performs a server-side redirect.

func (*Inertia) Respond

func (i *Inertia) Respond(c app.Context, filePath string, props map[string]any) error

Respond renders an Inertia page response for the given context.

func (*Inertia) ShareProp added in v0.1.2

func (i *Inertia) ShareProp(key string, val any)

ShareProp shares a prop globally across all pages.

func (*Inertia) ShareTemplateData added in v0.1.2

func (i *Inertia) ShareTemplateData(key string, val any)

ShareTemplateData makes a value available in the root template.

func (*Inertia) ShareTemplateFunc added in v0.1.2

func (i *Inertia) ShareTemplateFunc(key string, val any) error

ShareTemplateFunc makes a function available in the root template.

type InertiaResponse

type InertiaResponse struct {
	*Inertia
	// contains filtered or unexported fields
}

InertiaResponse implements the Renderer interface so it can be passed to app.Context.Render().

func (*InertiaResponse) Render

func (ir *InertiaResponse) Render(w io.Writer) error

Render satisfies the Renderer interface expected by app.Context.Render().

type JSONMarshaller added in v0.1.2

type JSONMarshaller interface {
	Decode(r io.Reader, v any) error
	Marshal(v any) ([]byte, error)
}

JSONMarshaller defines the interface for custom JSON serialization used internally by the Inertia page rendering pipeline.

type Logger added in v0.1.2

type Logger interface {
	Printf(format string, v ...any)
	Println(v ...any)
}

Logger defines the interface for logging within the Inertia package.

type MergeProps added in v0.1.2

type MergeProps struct {
	Value any
	// contains filtered or unexported fields
}

MergeProps is a property whose value is merged with previous values instead of being overwritten. https://inertiajs.com/merging-props

func DeepMerge added in v0.1.2

func DeepMerge(value any) MergeProps

DeepMerge creates a deep-mergeable prop value.

func Merge added in v0.1.2

func Merge(value any) MergeProps

Merge creates a mergeable prop value.

func (MergeProps) Append added in v0.1.2

func (p MergeProps) Append(paths ...string) MergeProps

Append marks the prop as appended (additive merge).

func (MergeProps) DeepMerge added in v0.1.2

func (p MergeProps) DeepMerge() MergeProps

DeepMerge sets the prop to deep-merge on subsequent updates.

func (MergeProps) MatchOn added in v0.1.2

func (p MergeProps) MatchOn(keys ...string) MergeProps

MatchOn restricts the merge behavior to only re-run when the listed keys change.

func (MergeProps) Merge added in v0.1.2

func (p MergeProps) Merge() MergeProps

Merge sets the prop to merge (append) on subsequent updates.

func (MergeProps) Prepend added in v0.1.2

func (p MergeProps) Prepend(paths ...string) MergeProps

Prepend marks the prop as prepended.

func (MergeProps) Prop added in v0.1.2

func (p MergeProps) Prop() any

type OnceProp added in v0.1.2

type OnceProp struct {
	Value any
}

OnceProp is a property sent only on the first visit, not on partial reloads unless explicitly requested. https://inertiajs.com/docs/v2/data-props/once-props

func Once added in v0.1.2

func Once(value any) OnceProp

Once creates a once-only prop value.

func (OnceProp) Prop added in v0.1.2

func (p OnceProp) Prop() any

type Option added in v0.1.2

type Option interface {
	Apply(*Config)
}

Option configures the Inertia instance. Users pass these to NewInertia (or Provider). The implementation never exposes gonertia to the caller.

func WithContainerID added in v0.1.2

func WithContainerID(id string) Option

WithContainerID sets the root container element id (default "app").

func WithEncryptHistory added in v0.1.2

func WithEncryptHistory() Option

WithEncryptHistory enables global history encryption.

func WithFlashProvider added in v0.1.2

func WithFlashProvider(p FlashProvider) Option

WithFlashProvider sets a custom flash data provider.

func WithJSONMarshaller added in v0.1.2

func WithJSONMarshaller(m JSONMarshaller) Option

WithJSONMarshaller sets a custom JSON marshaller for Inertia page data.

func WithLogger added in v0.1.2

func WithLogger(l Logger) Option

WithLogger sets a custom logger for the Inertia instance.

func WithSSR added in v0.1.2

func WithSSR() Option

WithSSR enables server-side rendering with auto-detection. In development mode, the Vite dev server URL is auto-detected from the hot file. In production, defaults to http://127.0.0.1:13714.

func WithSSRAt added in v0.1.2

func WithSSRAt(url string) Option

WithSSRAt enables server-side rendering at a custom URL.

func WithSSRHTTPClient added in v0.1.2

func WithSSRHTTPClient(client *http.Client) Option

WithSSRHTTPClient sets a custom HTTP client for SSR requests.

func WithVersion added in v0.1.2

func WithVersion(v string) Option

WithVersion sets the asset version by an arbitrary string.

func WithVersionFromFile added in v0.1.2

func WithVersionFromFile(path string) Option

WithVersionFromFile sets the asset version from a file's checksum.

func WithVersionFromFileFS added in v0.1.2

func WithVersionFromFileFS(fs any, path string) Option

WithVersionFromFileFS sets the asset version from a file checksum using an embedded filesystem (e.g. embed.FS).

func WithVite added in v0.1.2

func WithVite(opts ...ViteOption) Option

WithVite enables the full Vite integration with asset preloading, template helpers (viteAssets, viteRefresh, viteReactRefresh), and optional CSP support. When not used, a basic Vite setup (hot file + manifest resolution) is applied.

type OptionalProp added in v0.1.2

type OptionalProp struct {
	Value any
}

OptionalProp is a property evaluated only when requested in a partial reload. https://inertiajs.com/partial-reloads

func Optional added in v0.1.2

func Optional(value any) OptionalProp

Optional creates an optional (lazy) prop value.

func (OptionalProp) Prop added in v0.1.2

func (p OptionalProp) Prop() any

type PreloadStrategy added in v0.1.2

type PreloadStrategy string

PreloadStrategy controls how Vite assets are preloaded.

const (
	PreloadNone       PreloadStrategy = "none"
	PreloadAggressive PreloadStrategy = "aggressive"
	PreloadWaterfall  PreloadStrategy = "waterfall"
)

type Provider

type Provider struct {
	// RootTemplate is the path to the root HTML template file.
	// Defaults to InertiaRootTemplatePath if empty.
	RootTemplate string
	// Options applied during initialization.
	Options []Option
}

Provider implements app.Provider and bootstraps the Inertia instance.

func (*Provider) Provide

func (p *Provider) Provide(a app.App) error

type ScrollMetadata added in v0.1.2

type ScrollMetadata struct {
	PageName     string
	PreviousPage any
	NextPage     any
	CurrentPage  any
}

ScrollMetadata holds pagination metadata for infinite scroll.

type ScrollOption added in v0.1.2

type ScrollOption func(*ScrollProp)

ScrollOption configures a ScrollProp.

func WithMetadata added in v0.1.2

func WithMetadata(metadata ScrollMetadata) ScrollOption

WithMetadata sets pagination metadata for the scroll prop.

func WithWrapper added in v0.1.2

func WithWrapper(wrapper string) ScrollOption

WithWrapper sets a custom wrapper key for the scroll prop (defaults to "data").

type ScrollProp added in v0.1.2

type ScrollProp struct {
	Value    any
	Wrapper  string
	Metadata ScrollMetadata
}

ScrollProp is a property for infinite scrolling / pagination. https://inertiajs.com/infinite-scroll

func Scroll added in v0.1.2

func Scroll(value any, opts ...ScrollOption) ScrollProp

Scroll creates a scroll prop for infinite scrolling.

func (ScrollProp) Prop added in v0.1.2

func (p ScrollProp) Prop() any

type T added in v0.1.2

type T interface {
	Helper()
	Fatal(args ...any)
	Fatalf(format string, args ...any)
}

T is the minimal interface for testing helpers.

type ValidationErrors added in v0.1.2

type ValidationErrors map[string]any

ValidationErrors holds validation error messages keyed by field name.

func GetValidationErrors added in v0.1.2

func GetValidationErrors(ctx context.Context) ValidationErrors

GetValidationErrors retrieves validation errors from the context.

type ViteConfig added in v0.1.2

type ViteConfig struct {
	HotFile           string
	BuildManifest     string
	FallbackManifest  string
	BuildDir          string
	HotReloadPort     string
	EntryPoints       []string
	IntegrityEnabled  bool
	PreloadStrategy   PreloadStrategy
	PreloadConcurrent int
	EmbedFS           any // fs.FS for embedded manifest loading
}

ViteConfig holds Vite-specific settings for the Inertia instance. Applied via WithVite().

type ViteOption added in v0.1.2

type ViteOption func(*ViteConfig)

ViteOption configures the Vite integration.

func WithAggressivePreload added in v0.1.2

func WithAggressivePreload() ViteOption

WithAggressivePreload preloads all dependencies immediately.

func WithBuildDir added in v0.1.2

func WithBuildDir(dir string) ViteOption

WithBuildDir sets the build output directory.

func WithBuildManifest added in v0.1.2

func WithBuildManifest(path string) ViteOption

WithBuildManifest sets the build manifest path.

func WithEntryPoints added in v0.1.2

func WithEntryPoints(entries ...string) ViteOption

WithEntryPoints sets the entry points for asset generation.

func WithFallbackManifest added in v0.1.2

func WithFallbackManifest(path string) ViteOption

WithFallbackManifest sets the fallback manifest path.

func WithHotFile added in v0.1.2

func WithHotFile(path string) ViteOption

WithHotFile sets the hot reload file path.

func WithHotReloadPort added in v0.1.2

func WithHotReloadPort(port string) ViteOption

WithHotReloadPort sets the hot reload server port.

func WithIntegrity added in v0.1.2

func WithIntegrity() ViteOption

WithIntegrity enables SubResource Integrity (requires vite-plugin).

func WithViteEmbedFS added in v0.1.2

func WithViteEmbedFS(fs any) ViteOption

WithViteEmbedFS sets an embed.FS for production builds.

func WithWaterfallPreload added in v0.1.2

func WithWaterfallPreload(concurrent int) ViteOption

WithWaterfallPreload enables batched prefetch with concurrency control.

func WithoutPreloading added in v0.1.2

func WithoutPreloading() ViteOption

WithoutPreloading disables asset preloading (default).

Jump to

Keyboard shortcuts

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