Documentation
¶
Index ¶
- Variables
- func Back(w http.ResponseWriter, r *http.Request)
- func Initialize(config Config) error
- func Location(w http.ResponseWriter, r *http.Request, url string)
- func Middleware() router.MiddlewareFunc
- func Redirect(w http.ResponseWriter, r *http.Request, url string)
- func Render(w http.ResponseWriter, r *http.Request, component string, props Props) error
- func ResetForTesting()
- func SetSharePropsFunc(fn func(r *http.Request) (Props, error))
- func Share(key string, value any)
- func ShareFunc(key string, fn SharedPropFunc)
- func ShareMultiple(props Props)
- type AlwaysProp
- type Bond
- func (b *Bond) Back(w http.ResponseWriter, r *http.Request)
- func (b *Bond) ClearShared()
- func (b *Bond) ContainerID() string
- func (b *Bond) DecryptHistoryState(encrypted string) (*Page, error)
- func (b *Bond) EncryptHistoryState(page Page) (string, error)
- func (b *Bond) Location(w http.ResponseWriter, r *http.Request, url string)
- func (b *Bond) Middleware(next http.Handler) http.Handler
- func (b *Bond) MiddlewareFunc() router.MiddlewareFunc
- func (b *Bond) Redirect(w http.ResponseWriter, r *http.Request, url string)
- func (b *Bond) RedirectWithStatus(w http.ResponseWriter, r *http.Request, url string, status int)
- func (b *Bond) Render(w http.ResponseWriter, r *http.Request, component string, props Props) error
- func (b *Bond) Share(key string, value any)
- func (b *Bond) ShareFunc(key string, fn SharedPropFunc)
- func (b *Bond) ShareMultiple(props Props)
- func (b *Bond) Version() string
- type Config
- type DeferredProp
- type LazyProp
- type OptionalProp
- type Page
- type Props
- type SharedPropFunc
- type TemplateData
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotInitialized = errors.New("bond: not initialized") ErrInvalidTemplate = errors.New("bond: invalid template - must contain {{ .inertia }}") ErrTemplateRequired = errors.New("bond: template is required") )
Errors
Functions ¶
func Back ¶
func Back(w http.ResponseWriter, r *http.Request)
Back redirects to the previous page using the global instance
func Location ¶
func Location(w http.ResponseWriter, r *http.Request, url string)
Location forces a full page reload using the global instance
func Middleware ¶
func Middleware() router.MiddlewareFunc
Middleware returns router middleware using the global instance
func Redirect ¶
func Redirect(w http.ResponseWriter, r *http.Request, url string)
Redirect performs an SPA redirect using the global instance
func ResetForTesting ¶
func ResetForTesting()
ResetForTesting resets the global instance - exported for use by other packages in tests
func SetSharePropsFunc ¶
SetSharePropsFunc sets a function for per-request shared props This is a convenience wrapper matching the view package API The returned props are evaluated per-request and merged with component props
func ShareFunc ¶
func ShareFunc(key string, fn SharedPropFunc)
ShareFunc adds a dynamic shared prop using the global instance
func ShareMultiple ¶
func ShareMultiple(props Props)
ShareMultiple adds multiple shared props using the global instance
Types ¶
type AlwaysProp ¶
type AlwaysProp struct {
// contains filtered or unexported fields
}
AlwaysProp is always included in responses, even during partial reloads
func Always ¶
func Always(value any) AlwaysProp
Always creates a prop that is always included, even in partial reloads
type Bond ¶
type Bond struct {
// contains filtered or unexported fields
}
Bond is the main Inertia handler
func (*Bond) Back ¶
func (b *Bond) Back(w http.ResponseWriter, r *http.Request)
Back redirects to the previous page using the Referer header Falls back to "/" if no Referer is present
func (*Bond) ClearShared ¶
func (b *Bond) ClearShared()
ClearShared removes all shared props (useful for testing)
func (*Bond) ContainerID ¶
ContainerID returns the configured container ID
func (*Bond) DecryptHistoryState ¶
DecryptHistoryState decrypts page data from encrypted browser history
func (*Bond) EncryptHistoryState ¶
EncryptHistoryState encrypts page data for secure browser history storage Returns encrypted string or empty string if encryption is disabled
func (*Bond) Location ¶
Location forces a full page reload (external redirect) This breaks out of the SPA and performs a full navigation Use for external URLs or when you need to break out of Inertia
func (*Bond) Middleware ¶
Middleware returns HTTP middleware for Inertia protocol handling It performs version checking and sets appropriate headers
func (*Bond) MiddlewareFunc ¶
func (b *Bond) MiddlewareFunc() router.MiddlewareFunc
MiddlewareFunc returns Velocity router middleware
func (*Bond) Redirect ¶
Redirect performs an SPA-compatible redirect Uses 303 See Other for POST-Redirect-GET pattern
func (*Bond) RedirectWithStatus ¶
RedirectWithStatus performs a redirect with a custom status code
func (*Bond) ShareFunc ¶
func (b *Bond) ShareFunc(key string, fn SharedPropFunc)
ShareFunc adds a dynamic prop evaluated per-request
func (*Bond) ShareMultiple ¶
ShareMultiple adds multiple static props at once
type Config ¶
type Config struct {
RootTemplate string // Full HTML template with {{ .inertia }} placeholder
Version string // Asset version for cache busting
ContainerID string // Default: "app"
EncryptHistory bool // Use pkg/crypto for history state encryption
}
Config holds bond configuration
type DeferredProp ¶
type DeferredProp struct {
// contains filtered or unexported fields
}
DeferredProp is loaded after the initial page render by the client
func Defer ¶
func Defer(fn func() (any, error), group ...string) DeferredProp
Defer creates a deferred prop with an optional group name Deferred props are not included in the initial response but are fetched by the client after the page renders
func (DeferredProp) Evaluate ¶
func (d DeferredProp) Evaluate() (any, error)
Evaluate resolves the deferred prop value
func (DeferredProp) Group ¶
func (d DeferredProp) Group() string
Group returns the deferred prop's group name
type LazyProp ¶
type LazyProp struct {
// contains filtered or unexported fields
}
LazyProp is evaluated only when explicitly requested via partial reload
type OptionalProp ¶
type OptionalProp struct {
// contains filtered or unexported fields
}
OptionalProp is excluded from the first visit unless explicitly requested Similar to LazyProp but semantically different for API clarity
func Optional ¶
func Optional(fn func() (any, error)) OptionalProp
Optional creates an optional prop (same behavior as Lazy)
func (OptionalProp) Evaluate ¶
func (o OptionalProp) Evaluate() (any, error)
Evaluate resolves the optional prop value
type Page ¶
type Page struct {
Component string `json:"component"`
Props Props `json:"props"`
URL string `json:"url"`
Version string `json:"version"`
EncryptHistory bool `json:"encryptHistory,omitempty"`
ClearHistory bool `json:"clearHistory,omitempty"`
DeferredProps map[string][]string `json:"deferredProps,omitempty"`
}
Page represents an Inertia page response
func (Page) ToHTMLAttr ¶
ToHTMLAttr returns JSON escaped for use in HTML data attributes Single quotes in the JSON are escaped since we use data-page='...'
type SharedPropFunc ¶
SharedPropFunc is evaluated per-request for dynamic shared props