Documentation ¶
Index ¶
- func IsInertiaRequest(r *http.Request) bool
- type AssertableInertia
- type Inertia
- func (i *Inertia) Back(w http.ResponseWriter, r *http.Request, status ...int)
- func (i *Inertia) FlushSharedProps()
- func (i *Inertia) FlushSharedTemplateData()
- func (i *Inertia) FlushSharedTemplateFuncs()
- 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
- func (i *Inertia) WithValidationError(ctx context.Context, key string, msg any) context.Context
- func (i *Inertia) WithValidationErrors(ctx context.Context, errors ValidationErrors) 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
- type ValidationErrors
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsInertiaRequest ¶
IsInertiaRequest returns true if the request is an Inertia request.
Types ¶
type AssertableInertia ¶ added in v1.0.2
type AssertableInertia struct {
// contains filtered or unexported fields
}
AssertableInertia is an Inertia response struct with assert methods.
func Assert ¶ added in v1.0.4
func Assert(t t, body io.Reader) AssertableInertia
Assert creates AssertableInertia from the io.Reader body.
func AssertFromBytes ¶ added in v1.0.4
func AssertFromBytes(t t, body []byte) AssertableInertia
AssertFromBytes creates AssertableInertia from the bytes body.
func AssertFromString ¶ added in v1.0.4
func AssertFromString(t t, body string) AssertableInertia
AssertFromString creates AssertableInertia from the string body.
func (AssertableInertia) AssertComponent ¶ added in v1.0.2
func (i AssertableInertia) AssertComponent(want string)
AssertComponent verifies that component from Inertia response and the passed component are the same.
func (AssertableInertia) AssertProps ¶ added in v1.0.2
func (i AssertableInertia) AssertProps(want Props)
AssertProps verifies that props from Inertia response and the passed props are the same.
func (AssertableInertia) AssertURL ¶ added in v1.0.2
func (i AssertableInertia) AssertURL(want string)
AssertURL verifies that url from Inertia response and the passed url are the same.
func (AssertableInertia) AssertVersion ¶ added in v1.0.2
func (i AssertableInertia) AssertVersion(want string)
AssertVersion verifies that version from Inertia response and the passed version are the same.
type Inertia ¶
type Inertia struct {
// contains filtered or unexported fields
}
Inertia is a main Gonertia structure, which contains all the logic for being an Inertia 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) FlushSharedTemplateFuncs ¶ added in v1.0.1
func (i *Inertia) FlushSharedTemplateFuncs()
FlushSharedTemplateFuncs flushes the shared template func map.
func (*Inertia) Location ¶
Location creates redirect response.
If request was made by Inertia - sets 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 for GET, 303 for POST/PUT/PATCH).
func (*Inertia) Middleware ¶
Middleware returns Inertia middleware handler.
All of your handlers that can 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 returns response with Inertia data.
If request was made by Inertia - it will return data in JSON format. Otherwise, it will return HTML with 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.
func (*Inertia) WithTemplateData ¶
WithTemplateData appends template data value to the passed context.Context.
func (*Inertia) WithValidationError ¶ added in v1.0.5
WithValidationError appends validation error to the passed context.Context.
func (*Inertia) WithValidationErrors ¶ added in v1.0.5
func (i *Inertia) WithValidationErrors(ctx context.Context, errors ValidationErrors) context.Context
WithValidationErrors appends validation errors to the passed context.Context.
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 the data that will be transferred and will be available in the front-end component.
type TemplateData ¶
TemplateData are the data that will be transferred and will be available in the root template.
func TemplateDataFromContext ¶ added in v1.0.5
func TemplateDataFromContext(ctx context.Context) (TemplateData, error)
TemplateDataFromContext returns template data from the context.
type ValidationErrors ¶ added in v1.0.5
ValidationErrors are messages, that will be stored in the "errors" prop.
func ValidationErrorsFromContext ¶ added in v1.0.5
func ValidationErrorsFromContext(ctx context.Context) (ValidationErrors, error)
ValidationErrorsFromContext returns validation errors from the context.