Documentation ¶
Index ¶
- Constants
- func IsInertiaRequest(r *http.Request) bool
- type Inertia
- func (i *Inertia) FlushSharedProps()
- func (i *Inertia) FlushSharedTemplateData()
- func (i *Inertia) FlushSharedTemplateFunc()
- func (i *Inertia) Location(w http.ResponseWriter, r *http.Request, url string, status ...int)
- func (i *Inertia) Middleware(next http.Handler) http.Handler
- func (i *Inertia) Render(w http.ResponseWriter, r *http.Request, component string, props Props) (err 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)
- func (i *Inertia) SharedProp(key string) (any, bool)
- func (i *Inertia) SharedProps() Props
- func (i *Inertia) WithProp(ctx context.Context, key string, val any) context.Context
- func (i *Inertia) WithProps(ctx context.Context, props Props) context.Context
- func (i *Inertia) WithTemplateData(ctx context.Context, key string, val any) context.Context
- type LazyProp
- type Option
- func WithAssetURL(url string) Option
- func WithContainerID(id string) Option
- func WithLogger(log logger) Option
- func WithManifestFile(path string) Option
- func WithMarshalJSON(f marshallJSON) Option
- func WithTemplateFS(templateFS fs.FS) Option
- func WithVersion(version string) Option
- func WithoutLogger() Option
- type Props
- type TemplateData
Constants ¶
const ( // TemplateDataContextKey is the context key for template data. TemplateDataContextKey = contextKey(iota + 1) // PropsContextKey is the context key for props. PropsContextKey )
Variables ¶
This section is empty.
Functions ¶
func IsInertiaRequest ¶
IsInertiaRequest returns true if this request is Inertia request.
Types ¶
type Inertia ¶
type Inertia struct {
// contains filtered or unexported fields
}
Inertia is a structure that contain all logic of Inertia server adapter.
func (*Inertia) FlushSharedProps ¶
func (i *Inertia) FlushSharedProps()
FlushSharedProps flushes shared props.
func (*Inertia) FlushSharedTemplateData ¶
func (i *Inertia) FlushSharedTemplateData()
FlushSharedTemplateData flushes shared template data.
func (*Inertia) FlushSharedTemplateFunc ¶
func (i *Inertia) FlushSharedTemplateFunc()
FlushSharedTemplateFunc flushes the shared template func map.
func (*Inertia) Location ¶
Location creates redirect response.
If request is Inertia request, it will set status to 409 and url will be in "X-Inertia-Location" header. Otherwise, it will do an HTTP redirect with specified status (default is 302).
func (*Inertia) Middleware ¶
Middleware returns http.Handler with Inertia support.
All of your handlers that need to be handled by the Inertia should be under this middleware.
func (*Inertia) Render ¶
func (i *Inertia) Render(w http.ResponseWriter, r *http.Request, component string, props Props) (err error)
Render return response with Inertia data.
If request is Inertia request - it will return JSON. Otherwise, it will return root template.
func (*Inertia) ShareTemplateData ¶
ShareTemplateData adds passed data to shared template data.
func (*Inertia) ShareTemplateFunc ¶
ShareTemplateFunc adds passed value to the shared template func map.
func (*Inertia) SharedProp ¶
SharedProp return the shared prop.
func (*Inertia) SharedProps ¶
SharedProps returns shared props.
type Option ¶
Option is an option parameter that modifies Inertia.
func WithAssetURL ¶
WithAssetURL returns Option that will set Inertia's version based on asset url.
func WithContainerID ¶
WithContainerID returns Option that will set Inertia's container id.
func WithLogger ¶
func WithLogger(log logger) Option
WithLogger returns Option that will set Inertia's logger.
func WithManifestFile ¶
WithManifestFile returns Option that will set Inertia's version based on manifest file.
func WithMarshalJSON ¶
func WithMarshalJSON(f marshallJSON) Option
WithMarshalJSON returns Option that will set Inertia's marshallJSON func.
func WithTemplateFS ¶
WithTemplateFS returns Option that will set Inertia's templateFS.
func WithVersion ¶
WithVersion returns Option that will set Inertia's version.
func WithoutLogger ¶
func WithoutLogger() Option
WithoutLogger returns Option that will unset Inertia's logger. Actually set a logger with io.Discard output.
type Props ¶
Props are key-value data structure, that will be available in your front-end component.
type TemplateData ¶
TemplateData is a map with values that will be available in the root template.