Documentation
¶
Overview ¶
Package inertia implements the server-side parts of the Inertia protocol.
The package is built on net/http and has no runtime dependencies outside the Go standard library. Use New to create a Renderer, register Renderer.Middleware in your HTTP stack, and call Renderer.Render from handlers to return Inertia pages.
Framework adapters wrap Renderer instead of reimplementing protocol behavior. Flash data and validation errors are exposed through FlashStore; the package does not include a production session store.
Index ¶
- Constants
- Variables
- func AppendVary(h http.Header, value string)
- func ErrorBag(req *http.Request) string
- func ExceptOnceProps(req *http.Request) []string
- func InfiniteScrollMergeIntent(req *http.Request) string
- func IsInertiaRequest(req *http.Request) bool
- func IsPartialReload(req *http.Request) bool
- func IsPrecognition(req *http.Request) bool
- func IsPrefetch(req *http.Request) bool
- func PartialComponent(req *http.Request) string
- func PartialData(req *http.Request) []string
- func PartialExcept(req *http.Request) []string
- func PrecognitionErrors(w http.ResponseWriter, errors ValidationErrors) error
- func PrecognitionSuccess(w http.ResponseWriter)
- func PrecognitionValidateOnly(req *http.Request) []string
- func ResetProps(req *http.Request) []string
- func WithFlashContext(ctx context.Context, flash Flash) context.Context
- func WithProps(ctx context.Context, props Props) context.Context
- func WithSharedProps(ctx context.Context, props Props) context.Context
- func WithValidationErrorsContext(ctx context.Context, errors ValidationErrors) context.Context
- type ComponentExistenceChecker
- type ComponentExistsFunc
- type ComponentNameTransformer
- type ComponentNotFoundError
- type Config
- type DeferredFunc
- type DeferredProp
- type Flash
- type FlashData
- type FlashStore
- type JSONEncoder
- type MemoryFlashStore
- type MergeFunc
- type MergeProp
- type NoopFlashStore
- type OnceFunc
- type OnceProp
- type OncePropMetadata
- type Page
- type Prop
- func (p Prop) Always() Prop
- func (p Prop) Append(paths ...string) Prop
- func (p Prop) As(key string) Prop
- func (p Prop) DeepMerge() Prop
- func (p Prop) Defer(group ...string) Prop
- func (p Prop) Fresh(fresh ...bool) Prop
- func (p Prop) MatchOn(paths ...string) Prop
- func (p Prop) Merge() Prop
- func (p Prop) Once() Prop
- func (p Prop) Optional() Prop
- func (p Prop) Prepend(paths ...string) Prop
- func (p Prop) Rescue(rescue ...bool) Prop
- func (p Prop) Scroll(metadata ScrollMetadata) Prop
- func (p Prop) Until(t time.Time) Prop
- func (p Prop) Wrapper(path string) Prop
- type PropFunc
- type Props
- type RedirectOption
- type RenderOption
- func WithClearHistory(clear ...bool) RenderOption
- func WithEncryptHistory(encrypt ...bool) RenderOption
- func WithInertiaHead(head template.HTML) RenderOption
- func WithRenderPreserveFragment() RenderOption
- func WithRenderStatus(code int) RenderOption
- func WithViewData(data map[string]any) RenderOption
- func WithViteTags(tags template.HTML) RenderOption
- type Renderer
- func (r *Renderer) Back(w http.ResponseWriter, req *http.Request, opts ...RedirectOption) error
- func (r *Renderer) Location(w http.ResponseWriter, req *http.Request, url string) error
- func (r *Renderer) Middleware(next http.Handler) http.Handler
- func (r *Renderer) Redirect(w http.ResponseWriter, req *http.Request, url string, opts ...RedirectOption) error
- func (r *Renderer) Render(w http.ResponseWriter, req *http.Request, component string, props Props, ...) error
- func (r *Renderer) RenderError(w http.ResponseWriter, req *http.Request, component string, props Props, ...) error
- type RootView
- type RootViewData
- type ScrollFunc
- type ScrollMetadata
- type ScrollPaginator
- type ScrollProp
- type SharedPropsFunc
- type SharedPropsProvider
- type StandardJSONEncoder
- type TemplateRootView
- type URLResolver
- type URLResolverFunc
- type ValidationErrors
- type VersionProvider
- type VersionProviderFunc
- type Vite
- type ViteConfig
Constants ¶
const ( // HeaderInertia is the request and response header that marks an Inertia request or response. HeaderInertia = "X-Inertia" // HeaderInertiaVersion carries the client asset version. HeaderInertiaVersion = "X-Inertia-Version" // HeaderInertiaLocation carries the target URL for an Inertia location visit. HeaderInertiaLocation = "X-Inertia-Location" // HeaderInertiaRedirect carries a redirect target that should preserve the URL fragment. HeaderInertiaRedirect = "X-Inertia-Redirect" // HeaderInertiaPartialComponent carries the component name for a partial reload. HeaderInertiaPartialComponent = "X-Inertia-Partial-Component" // HeaderInertiaPartialData carries the prop names to include in a partial reload. HeaderInertiaPartialData = "X-Inertia-Partial-Data" // HeaderInertiaPartialExcept carries the prop names to exclude in a partial reload. HeaderInertiaPartialExcept = "X-Inertia-Partial-Except" // HeaderInertiaReset carries the prop names to reset before merging. HeaderInertiaReset = "X-Inertia-Reset" // HeaderInertiaErrorBag carries the requested validation error bag name. HeaderInertiaErrorBag = "X-Inertia-Error-Bag" // HeaderInertiaInfiniteScrollMergeIntent carries append or prepend intent for infinite scroll. HeaderInertiaInfiniteScrollMergeIntent = "X-Inertia-Infinite-Scroll-Merge-Intent" // HeaderInertiaExceptOnceProps carries once prop keys already loaded by the client. HeaderInertiaExceptOnceProps = "X-Inertia-Except-Once-Props" // HeaderPurpose carries request purpose hints such as prefetch. HeaderPurpose = "Purpose" // HeaderPrecognition marks Precognition validation requests and responses. HeaderPrecognition = "Precognition" // HeaderPrecognitionValidateOnly carries field names to validate during Precognition. HeaderPrecognitionValidateOnly = "Precognition-Validate-Only" // HeaderPrecognitionSuccess marks successful Precognition validation responses. HeaderPrecognitionSuccess = "Precognition-Success" )
Variables ¶
var ( // ErrMissingRootView is returned when Config.RootView is not set. ErrMissingRootView = errors.New("inertia: missing root view") // ErrMissingFlashStore is returned when flash data is used without a FlashStore. ErrMissingFlashStore = errors.New("inertia: flash store is not configured") // ErrInvalidComponent is returned when a render call receives an empty component name. ErrInvalidComponent = errors.New("inertia: component must not be empty") // ErrComponentNotFound is returned when a configured component checker cannot find a component. ErrComponentNotFound = errors.New("inertia: component not found") // ErrInvalidScrollPaginator is returned when ScrollPage receives a nil paginator. ErrInvalidScrollPaginator = errors.New("inertia: scroll paginator is nil") )
Functions ¶
func AppendVary ¶
AppendVary appends value to the Vary header without duplicating existing values.
func ExceptOnceProps ¶ added in v0.2.0
ExceptOnceProps returns once prop keys the client has already loaded.
func InfiniteScrollMergeIntent ¶ added in v0.2.0
InfiniteScrollMergeIntent returns the requested infinite scroll merge intent.
func IsInertiaRequest ¶
IsInertiaRequest reports whether req is an Inertia request.
func IsPartialReload ¶
IsPartialReload reports whether req asks for a partial reload.
func IsPrecognition ¶ added in v0.2.0
IsPrecognition reports whether req is a Precognition validation request.
func IsPrefetch ¶ added in v0.2.0
IsPrefetch reports whether req is an Inertia prefetch request.
func PartialComponent ¶
PartialComponent returns the partial reload component name from req.
func PartialData ¶
PartialData returns the requested partial reload prop names from req.
func PartialExcept ¶
PartialExcept returns the excluded partial reload prop names from req.
func PrecognitionErrors ¶ added in v0.2.0
func PrecognitionErrors(w http.ResponseWriter, errors ValidationErrors) error
PrecognitionErrors writes a failed Precognition validation response.
func PrecognitionSuccess ¶ added in v0.2.0
func PrecognitionSuccess(w http.ResponseWriter)
PrecognitionSuccess writes a successful Precognition validation response.
func PrecognitionValidateOnly ¶ added in v0.2.0
PrecognitionValidateOnly returns field names requested for Precognition validation.
func ResetProps ¶ added in v0.2.0
ResetProps returns prop names the client wants to reset before merging.
func WithFlashContext ¶
WithFlashContext stores flash data in ctx for the current request.
func WithSharedProps ¶
WithSharedProps stores request-scoped shared props in ctx.
func WithValidationErrorsContext ¶
func WithValidationErrorsContext(ctx context.Context, errors ValidationErrors) context.Context
WithValidationErrorsContext stores validation errors in ctx for the current request.
Types ¶
type ComponentExistenceChecker ¶ added in v0.3.0
type ComponentExistenceChecker interface {
// ComponentExists reports whether component exists.
ComponentExists(component string) (bool, error)
}
ComponentExistenceChecker checks whether a component exists.
type ComponentExistsFunc ¶ added in v0.3.0
ComponentExistsFunc adapts a function to ComponentExistenceChecker.
func (ComponentExistsFunc) ComponentExists ¶ added in v0.3.0
func (f ComponentExistsFunc) ComponentExists(component string) (bool, error)
ComponentExists calls f(component).
type ComponentNameTransformer ¶ added in v0.3.0
ComponentNameTransformer transforms component names before rendering.
type ComponentNotFoundError ¶ added in v0.3.0
type ComponentNotFoundError struct {
// Component is the transformed component name that was checked.
Component string
}
ComponentNotFoundError is returned when a configured checker cannot find a component.
func (ComponentNotFoundError) Error ¶ added in v0.3.0
func (e ComponentNotFoundError) Error() string
Error returns the error message.
func (ComponentNotFoundError) Is ¶ added in v0.3.0
func (e ComponentNotFoundError) Is(target error) bool
Is reports whether target is ErrComponentNotFound.
type Config ¶
type Config struct {
// RootView renders the initial HTML document.
RootView RootView
// VersionProvider returns the current asset version.
VersionProvider VersionProvider
SharedProps SharedPropsProvider
// FlashStore stores one-time flash data and validation errors across redirects.
FlashStore FlashStore
// URLResolver returns the URL written into the Inertia page object.
URLResolver URLResolver
// JSONEncoder encodes Inertia page objects.
JSONEncoder JSONEncoder
// DefaultRenderOptions are applied to every Render call before request options.
DefaultRenderOptions []RenderOption
// ComponentNameTransformer transforms component names before rendering.
ComponentNameTransformer ComponentNameTransformer
// ComponentExistenceChecker checks transformed component names before rendering.
ComponentExistenceChecker ComponentExistenceChecker
}
Config configures a Renderer.
type DeferredFunc ¶ added in v0.2.0
type DeferredFunc = PropFunc
DeferredFunc loads a deferred prop for req.
type DeferredProp ¶ added in v0.2.0
type DeferredProp = Prop
DeferredProp marks a page prop as deferred until a matching partial reload.
func Defer ¶ added in v0.2.0
func Defer(fn DeferredFunc, group ...string) DeferredProp
Defer returns a prop that is omitted from the initial page response.
type Flash ¶
type Flash Props
Flash is the set of one-time props sent after a redirect.
func FlashFromContext ¶
FlashFromContext returns flash data stored in ctx.
type FlashData ¶
type FlashData struct {
// Flash contains one-time flash props.
Flash Flash
// Errors contains default validation errors.
Errors ValidationErrors
// Bags contains named validation error bags.
Bags map[string]ValidationErrors
}
FlashData is the data stored by a FlashStore.
type FlashStore ¶
type FlashStore interface {
// Pull reads and clears flash data for req.
Pull(req *http.Request) (FlashData, error)
// Put stores flash data for the next request.
Put(w http.ResponseWriter, req *http.Request, data FlashData) error
// Reflash preserves existing flash data for another request.
Reflash(w http.ResponseWriter, req *http.Request) error
}
FlashStore stores one-time flash data and validation errors across redirects.
type JSONEncoder ¶
type JSONEncoder interface {
// Encode returns the JSON representation of v.
Encode(v any) ([]byte, error)
}
JSONEncoder encodes values for Inertia JSON responses.
type MemoryFlashStore ¶ added in v0.1.1
type MemoryFlashStore struct {
CookieName string
CookiePath string
CookieSecure bool
CookieSameSite http.SameSite
// contains filtered or unexported fields
}
func NewMemoryFlashStore ¶ added in v0.1.1
func NewMemoryFlashStore() *MemoryFlashStore
func (*MemoryFlashStore) Pull ¶ added in v0.1.1
func (s *MemoryFlashStore) Pull(req *http.Request) (FlashData, error)
func (*MemoryFlashStore) Put ¶ added in v0.1.1
func (s *MemoryFlashStore) Put(w http.ResponseWriter, req *http.Request, data FlashData) error
func (*MemoryFlashStore) Reflash ¶ added in v0.1.1
func (s *MemoryFlashStore) Reflash(w http.ResponseWriter, req *http.Request) error
type MergeFunc ¶ added in v0.2.0
type MergeFunc = PropFunc
MergeFunc loads a mergeable prop for req.
type MergeProp ¶ added in v0.2.0
type MergeProp = Prop
MergeProp marks a page prop as mergeable during partial reloads.
type NoopFlashStore ¶
type NoopFlashStore struct{}
NoopFlashStore is a FlashStore implementation that stores no data.
func (NoopFlashStore) Pull ¶
func (NoopFlashStore) Pull(req *http.Request) (FlashData, error)
Pull returns no flash data.
func (NoopFlashStore) Put ¶
func (NoopFlashStore) Put(w http.ResponseWriter, req *http.Request, data FlashData) error
Put ignores data.
func (NoopFlashStore) Reflash ¶
func (NoopFlashStore) Reflash(w http.ResponseWriter, req *http.Request) error
Reflash does nothing.
type OnceFunc ¶ added in v0.2.0
type OnceFunc = PropFunc
OnceFunc loads a prop that the Inertia client remembers across visits.
type OnceProp ¶ added in v0.2.0
type OnceProp = Prop
OnceProp marks a page prop as reusable after the client receives it once.
type OncePropMetadata ¶ added in v0.2.0
type OncePropMetadata struct {
// Prop is the page prop path reused by the client.
Prop string `json:"prop"`
// ExpiresAt is a Unix millisecond timestamp, or nil when the prop does not expire.
ExpiresAt *int64 `json:"expiresAt"`
}
OncePropMetadata describes an Inertia once prop entry in the page object.
type Page ¶
type Page struct {
// Component is the client-side component name.
Component string `json:"component"`
// Props contains the data for the client-side component.
Props Props `json:"props"`
// URL is the current request URL as seen by Inertia.
URL string `json:"url"`
// Version is the current asset version.
Version any `json:"version,omitempty"`
// EncryptHistory requests encrypted browser history state when supported by the client.
EncryptHistory bool `json:"encryptHistory,omitempty"`
// ClearHistory requests clearing browser history state when supported by the client.
ClearHistory bool `json:"clearHistory,omitempty"`
// PreserveFragment requests preserving the current URL fragment when supported by the client.
PreserveFragment bool `json:"preserveFragment,omitempty"`
// RescuedProps lists deferred props that failed and were rescued.
RescuedProps []string `json:"rescuedProps,omitempty"`
SharedProps []string `json:"sharedProps,omitempty"`
// MergeProps lists prop paths that should be appended during navigation.
MergeProps []string `json:"mergeProps,omitempty"`
// PrependProps lists prop paths that should be prepended during navigation.
PrependProps []string `json:"prependProps,omitempty"`
// DeepMergeProps lists prop paths that should be deeply merged during navigation.
DeepMergeProps []string `json:"deepMergeProps,omitempty"`
// MatchPropsOn lists prop paths used to match items while merging arrays.
MatchPropsOn []string `json:"matchPropsOn,omitempty"`
// ScrollProps contains infinite scroll metadata keyed by prop name.
ScrollProps map[string]ScrollMetadata `json:"scrollProps,omitempty"`
// DeferredProps groups deferred prop names by request group.
DeferredProps map[string][]string `json:"deferredProps,omitempty"`
// OnceProps contains once prop metadata keyed by once prop key.
OnceProps map[string]OncePropMetadata `json:"onceProps,omitempty"`
}
Page is the Inertia page object sent to the browser.
type Prop ¶ added in v0.2.0
type Prop struct {
// contains filtered or unexported fields
}
Prop is a page prop with optional Inertia protocol modifiers.
func Lazy ¶ added in v0.2.0
Lazy returns a prop that is evaluated only when the response includes it.
func Optional ¶ added in v0.2.0
Optional returns a prop that is only included when explicitly requested.
func (Prop) Always ¶ added in v0.2.0
Always returns p configured to be included even during partial reloads.
func (Prop) Append ¶ added in v0.2.0
Append returns p configured to append the given relative prop paths.
func (Prop) As ¶ added in v0.2.0
As returns p with a custom once key shared across matching once props.
func (Prop) DeepMerge ¶ added in v0.2.0
DeepMerge returns p configured to deeply merge the whole prop.
func (Prop) Fresh ¶ added in v0.2.0
Fresh returns p configured to ignore the client's remembered once value.
func (Prop) MatchOn ¶ added in v0.2.0
MatchOn returns p configured to match merged items by the given relative paths.
func (Prop) Once ¶ added in v0.2.0
Once returns p configured to be reused by the client after it is loaded.
func (Prop) Optional ¶ added in v0.2.0
Optional returns p configured to be included only when explicitly requested.
func (Prop) Prepend ¶ added in v0.2.0
Prepend returns p configured to prepend the given relative prop paths.
func (Prop) Rescue ¶ added in v0.3.0
Rescue omits a failed deferred prop and marks it in Page.RescuedProps.
func (Prop) Scroll ¶ added in v0.3.0
func (p Prop) Scroll(metadata ScrollMetadata) Prop
Scroll returns p configured as an infinite scroll prop.
type Props ¶
Props is the set of top-level props sent to the Inertia page component.
func PropsFromContext ¶
PropsFromContext returns request-scoped props from ctx.
func SharedPropsFromContext ¶
SharedPropsFromContext returns request-scoped shared props from ctx.
type RedirectOption ¶
type RedirectOption func(*redirectOptions)
RedirectOption configures a redirect response.
func WithErrorBag ¶
func WithErrorBag(name string) RedirectOption
WithErrorBag stores validation errors in the named error bag.
func WithFlash ¶
func WithFlash(data Flash) RedirectOption
WithFlash stores flash data for the next request.
func WithPreserveFragment ¶
func WithPreserveFragment() RedirectOption
WithPreserveFragment requests an Inertia redirect that preserves the URL fragment.
func WithStatus ¶
func WithStatus(code int) RedirectOption
WithStatus overrides the HTTP redirect status.
func WithValidationErrors ¶
func WithValidationErrors(errors ValidationErrors) RedirectOption
WithValidationErrors stores validation errors for the next request.
type RenderOption ¶
type RenderOption func(*renderOptions)
RenderOption configures a single Render call.
func WithClearHistory ¶ added in v0.2.0
func WithClearHistory(clear ...bool) RenderOption
WithClearHistory sets Page.ClearHistory for the rendered page.
func WithEncryptHistory ¶ added in v0.2.0
func WithEncryptHistory(encrypt ...bool) RenderOption
WithEncryptHistory sets Page.EncryptHistory for the rendered page.
func WithInertiaHead ¶
func WithInertiaHead(head template.HTML) RenderOption
WithInertiaHead sets HTML that should be rendered in the Inertia head placeholder.
func WithRenderPreserveFragment ¶
func WithRenderPreserveFragment() RenderOption
WithRenderPreserveFragment sets Page.PreserveFragment for the rendered page.
func WithRenderStatus ¶ added in v0.3.0
func WithRenderStatus(code int) RenderOption
WithRenderStatus sets the HTTP status code for a rendered page.
func WithViewData ¶
func WithViewData(data map[string]any) RenderOption
WithViewData adds extra data for the RootView template.
func WithViteTags ¶
func WithViteTags(tags template.HTML) RenderOption
WithViteTags sets HTML tags generated by Vite.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer renders Inertia pages, handles protocol middleware, and creates Inertia redirects.
func (*Renderer) Back ¶
func (r *Renderer) Back(w http.ResponseWriter, req *http.Request, opts ...RedirectOption) error
Back redirects to the Referer header or to "/" when no Referer is present.
func (*Renderer) Location ¶
Location sends an Inertia location response or a normal redirect for non-Inertia requests.
func (*Renderer) Middleware ¶
Middleware returns an HTTP middleware that handles Inertia protocol concerns.
func (*Renderer) Redirect ¶
func (r *Renderer) Redirect(w http.ResponseWriter, req *http.Request, url string, opts ...RedirectOption) error
Redirect sends a redirect response and stores flash data when configured.
func (*Renderer) Render ¶
func (r *Renderer) Render(w http.ResponseWriter, req *http.Request, component string, props Props, opts ...RenderOption) error
Render renders an Inertia page.
For Inertia requests it writes a JSON page response. For normal browser visits it renders the configured RootView.
func (*Renderer) RenderError ¶ added in v0.3.0
func (r *Renderer) RenderError(w http.ResponseWriter, req *http.Request, component string, props Props, status int, opts ...RenderOption) error
RenderError renders an Inertia error page with status.
type RootView ¶
type RootView interface {
// Render writes the root document using data.
Render(w io.Writer, data RootViewData) error
}
RootView renders the root HTML document for initial browser visits.
func NewTemplateRootView ¶
NewTemplateRootView creates a RootView from t and template name.
func NewTemplateRootViewFromFS ¶
NewTemplateRootViewFromFS parses path from fsys and returns a RootView.
type RootViewData ¶
type RootViewData struct {
// Page is the Inertia page object.
Page Page
// PageJSON is the safe JSON representation of Page.
PageJSON template.JS
// InertiaScript is the script tag containing PageJSON.
InertiaScript template.HTML
// InertiaHead is HTML rendered in the document head.
InertiaHead template.HTML
// ViteTags contains script and stylesheet tags for Vite assets.
ViteTags template.HTML
// Data contains additional template data.
Data map[string]any
}
RootViewData contains the data passed to a RootView.
type ScrollFunc ¶ added in v0.2.0
type ScrollFunc = PropFunc
ScrollFunc loads an infinite scroll prop for req.
type ScrollMetadata ¶ added in v0.2.0
type ScrollMetadata struct {
// PageName is the query parameter used for this scroll container.
PageName string `json:"pageName"`
// PreviousPage is the previous page value, or nil when there is no previous page.
PreviousPage any `json:"previousPage"`
// NextPage is the next page value, or nil when there is no next page.
NextPage any `json:"nextPage"`
// CurrentPage is the current page value.
CurrentPage any `json:"currentPage"`
// Reset marks the scroll prop as reset for the current response.
Reset bool `json:"reset,omitempty"`
}
ScrollMetadata describes pagination state for an infinite scroll prop.
type ScrollPaginator ¶ added in v0.3.0
type ScrollPaginator interface {
// ScrollItems returns the items for the current page.
ScrollItems() any
// ScrollMetadata returns the pagination state for the current page.
ScrollMetadata() ScrollMetadata
}
ScrollPaginator exposes paginated data in the shape required by ScrollPage.
type ScrollProp ¶ added in v0.2.0
type ScrollProp = Prop
ScrollProp marks a page prop as an infinite scroll prop.
func Scroll ¶ added in v0.2.0
func Scroll(value any, metadata ScrollMetadata) ScrollProp
Scroll returns an infinite scroll prop with explicit pagination metadata.
func ScrollPage ¶ added in v0.3.0
func ScrollPage(paginator ScrollPaginator, wrapper ...string) ScrollProp
ScrollPage returns an infinite scroll prop from a paginator interface.
type SharedPropsFunc ¶
SharedPropsFunc adapts a function to SharedPropsProvider.
type SharedPropsProvider ¶
SharedPropsProvider returns props that are shared by every Inertia page.
func NoSharedProps ¶
func NoSharedProps() SharedPropsProvider
NoSharedProps returns a provider that returns no shared props.
func StaticSharedProps ¶
func StaticSharedProps(props Props) SharedPropsProvider
StaticSharedProps returns a provider that always returns props.
type StandardJSONEncoder ¶
type StandardJSONEncoder struct{}
StandardJSONEncoder encodes values with encoding/json.
type TemplateRootView ¶
type TemplateRootView struct {
// contains filtered or unexported fields
}
TemplateRootView renders a RootView with html/template.
func (*TemplateRootView) Render ¶
func (v *TemplateRootView) Render(w io.Writer, data RootViewData) error
Render executes the configured template.
type URLResolver ¶
URLResolver returns the URL stored in the Inertia page object.
type URLResolverFunc ¶
URLResolverFunc adapts a function to URLResolver.
type ValidationErrors ¶
ValidationErrors is a map of validation error values keyed by field or bag name.
func ValidationErrorsFromContext ¶
func ValidationErrorsFromContext(ctx context.Context) ValidationErrors
ValidationErrorsFromContext returns validation errors stored in ctx.
type VersionProvider ¶
type VersionProvider interface {
// Version returns the current asset version.
Version(ctx context.Context) (any, error)
}
VersionProvider returns the current Inertia asset version.
func StaticVersion ¶
func StaticVersion(version any) VersionProvider
StaticVersion returns a provider that always returns version.
func VersionFromFSFileHash ¶
func VersionFromFSFileHash(fsys fs.FS, path string) VersionProvider
VersionFromFSFileHash returns a provider that hashes a file from fsys.
func VersionFromFileHash ¶
func VersionFromFileHash(path string) VersionProvider
VersionFromFileHash returns a provider that hashes the file at path.
type VersionProviderFunc ¶
VersionProviderFunc adapts a function to VersionProvider.
type Vite ¶
type Vite struct {
// contains filtered or unexported fields
}
Vite generates script and stylesheet tags for Vite assets.
func NewVite ¶
func NewVite(config ViteConfig) (*Vite, error)
NewVite creates a Vite helper from config.
func (*Vite) VersionProvider ¶
func (v *Vite) VersionProvider() VersionProvider
VersionProvider returns a VersionProvider based on the Vite configuration.
type ViteConfig ¶
type ViteConfig struct {
// ManifestPath is the path to Vite's manifest file.
ManifestPath string
// ManifestFS is the optional filesystem used to read ManifestPath.
ManifestFS fs.FS
// PublicPath is the public URL prefix for built assets.
PublicPath string
// Entry is the Vite entrypoint key in the manifest.
Entry string
// DevServerURL enables development mode when set.
DevServerURL string
// ReactRefresh enables the React refresh preamble in development mode.
ReactRefresh bool
}
ViteConfig configures Vite asset tag generation.