Documentation
¶
Index ¶
- Constants
- func AddFlash(ctx context.Context, flash Flash) context.Context
- func AddValidationErrors(ctx context.Context, errors ValidationErrors) context.Context
- func Back(c app.Context)
- func ClearHistory(ctx context.Context) context.Context
- func GetProps(ctx context.Context) map[string]any
- func GetTemplateData(ctx context.Context) map[string]any
- func IsInertiaRequest(r *http.Request) bool
- func Location(c app.Context, url string, status ...int)
- func Redirect(c app.Context, url string)
- func Respond(c app.Context, filePath string, props map[string]any) error
- func SetEncryptHistory(ctx context.Context, encrypt ...bool) context.Context
- func SetFlash(ctx context.Context, flash Flash) context.Context
- func SetFlashValue(ctx context.Context, key string, val any) context.Context
- func SetProp(ctx context.Context, key string, val any) context.Context
- func SetProps(ctx context.Context, props map[string]any) context.Context
- func SetTemplateData(ctx context.Context, data map[string]any) context.Context
- func SetTemplateDatum(ctx context.Context, key string, val any) context.Context
- func SetValidationError(ctx context.Context, key string, msg string) context.Context
- func SetValidationErrors(ctx context.Context, errors ValidationErrors) context.Context
- func Vite(manifestPath, buildDir string) func(p string) (string, error)
- type AlwaysProp
- type Assertable
- func (a Assertable) AssertClearHistory(want bool)
- func (a Assertable) AssertComponent(want string)
- func (a Assertable) AssertDeferredProps(want map[string][]string)
- func (a Assertable) AssertEncryptHistory(want bool)
- func (a Assertable) AssertMergeProps(want []string)
- func (a Assertable) AssertProps(want map[string]any)
- func (a Assertable) AssertURL(want string)
- func (a Assertable) AssertVersion(want string)
- func (a Assertable) ClearHistory() bool
- func (a Assertable) Component() string
- func (a Assertable) DeepMergeProps() []string
- func (a Assertable) DeferredProps() map[string][]string
- func (a Assertable) EncryptHistory() bool
- func (a Assertable) MatchPropsOn() []string
- func (a Assertable) MergeProps() []string
- func (a Assertable) PrependProps() []string
- func (a Assertable) Props() map[string]any
- func (a Assertable) ScrollProps() map[string]map[string]any
- func (a Assertable) URL() string
- func (a Assertable) Version() string
- type Config
- type DeferProp
- type Flash
- type FlashProvider
- type Inertia
- func (i *Inertia) Back(c app.Context)
- func (i *Inertia) Location(c app.Context, url string, status ...int)
- func (i *Inertia) Middleware(next http.Handler) http.Handler
- func (i *Inertia) Redirect(c app.Context, url string)
- func (i *Inertia) Respond(c app.Context, filePath string, props map[string]any) error
- func (i *Inertia) ShareProp(key string, val any)
- func (i *Inertia) ShareTemplateData(key string, val any)
- func (i *Inertia) ShareTemplateFunc(key string, val any) error
- type InertiaResponse
- type JSONMarshaller
- type Logger
- type MergeProps
- type OnceProp
- type Option
- func WithContainerID(id string) Option
- func WithEncryptHistory() Option
- func WithFlashProvider(p FlashProvider) Option
- func WithJSONMarshaller(m JSONMarshaller) Option
- func WithLogger(l Logger) Option
- func WithSSR() Option
- func WithSSRAt(url string) Option
- func WithSSRHTTPClient(client *http.Client) Option
- func WithVersion(v string) Option
- func WithVersionFromFile(path string) Option
- func WithVersionFromFileFS(fs any, path string) Option
- func WithVite(opts ...ViteOption) Option
- type OptionalProp
- type PreloadStrategy
- type Provider
- type ScrollMetadata
- type ScrollOption
- type ScrollProp
- type T
- type ValidationErrors
- type ViteConfig
- type ViteOption
- func WithAggressivePreload() ViteOption
- func WithBuildDir(dir string) ViteOption
- func WithBuildManifest(path string) ViteOption
- func WithEntryPoints(entries ...string) ViteOption
- func WithFallbackManifest(path string) ViteOption
- func WithHotFile(path string) ViteOption
- func WithHotReloadPort(port string) ViteOption
- func WithIntegrity() ViteOption
- func WithViteEmbedFS(fs any) ViteOption
- func WithWaterfallPreload(concurrent int) ViteOption
- func WithoutPreloading() ViteOption
Constants ¶
const InertiaBuildPath = "/public/build/"
const InertiaManifestPath = "./public/build/manifest.json"
const InertiaRootTemplatePath = "resources/views/root.html"
const ViteHotPath = "./public/hot"
Variables ¶
This section is empty.
Functions ¶
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
Back redirects the user to the previous URL via the registered Inertia instance.
func ClearHistory ¶ added in v0.1.2
ClearHistory marks that history should be cleared on the next request.
func GetTemplateData ¶ added in v0.1.2
GetTemplateData retrieves template data from the context.
func IsInertiaRequest ¶ added in v0.1.2
IsInertiaRequest returns true if the request was made by the Inertia client.
func Location ¶ added in v0.1.2
Location performs an external redirect via the registered Inertia instance.
func Redirect ¶ added in v0.1.2
Redirect performs a server-side redirect via the registered Inertia instance.
func Respond ¶
Respond renders an Inertia page response. Validation errors from the session are automatically merged into props.
func SetEncryptHistory ¶ added in v0.1.2
SetEncryptHistory enables or disables history encryption for the next request.
func SetFlash ¶ added in v0.1.2
SetFlash stores flash data on the context for the next Inertia request.
func SetFlashValue ¶ added in v0.1.2
SetFlashValue stores a single flash value on the context.
func SetProps ¶ added in v0.1.2
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
SetTemplateData stores template data on the context. Values set this way are available in the root template.
func SetTemplateDatum ¶ added in v0.1.2
SetTemplateDatum stores a single template datum on the context.
func SetValidationError ¶ added in v0.1.2
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.
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
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
DeferProp is a property evaluated after the page has loaded. https://inertiajs.com/deferred-props
func Defer ¶ added in v0.1.2
Defer creates a deferred prop value that loads after the initial page render.
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.
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 NewInertia ¶
NewInertia creates a new Inertia instance. It is retained for compatibility with the original API. New code should use NewInertiaWithError so setup failures can be handled explicitly. It returns nil when initialization fails; it never terminates the process.
func NewInertiaWithError ¶ added in v0.1.6
NewInertiaWithError creates a new Inertia instance and returns any setup error. User-supplied Options are collected into a Config, then translated into gonertia options internally.
func (*Inertia) Location ¶ added in v0.1.2
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
Middleware returns an HTTP middleware that handles Inertia request detection, version checks, flash data resolution, and response wrapping.
func (*Inertia) ShareTemplateData ¶ added in v0.1.2
ShareTemplateData makes a value 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().
type JSONMarshaller ¶ added in v0.1.2
JSONMarshaller defines the interface for custom JSON serialization used internally by the Inertia page rendering pipeline.
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 (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
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
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
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 WithSSRHTTPClient ¶ added in v0.1.2
WithSSRHTTPClient sets a custom HTTP client for SSR requests.
func WithVersion ¶ added in v0.1.2
WithVersion sets the asset version by an arbitrary string.
func WithVersionFromFile ¶ added in v0.1.2
WithVersionFromFile sets the asset version from a file's checksum.
func WithVersionFromFileFS ¶ added in v0.1.2
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.
type ScrollMetadata ¶ added in v0.1.2
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 ValidationErrors ¶ added in v0.1.2
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).