Documentation ¶
Index ¶
- func AddValidationErrors(ctx context.Context, errors ValidationErrors) context.Context
- func ClearHistory(ctx context.Context) context.Context
- func ClearHistoryFromContext(ctx context.Context) bool
- func EncryptHistoryFromContext(ctx context.Context) (bool, bool)
- func IsInertiaRequest(r *http.Request) bool
- func SetEncryptHistory(ctx context.Context, encrypt ...bool) context.Context
- func SetProp(ctx context.Context, key string, val any) context.Context
- func SetProps(ctx context.Context, props Props) context.Context
- func SetTemplateData(ctx context.Context, templateData TemplateData) 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
- type AlwaysProp
- type AssertableInertia
- func (i AssertableInertia) AssertClearHistory(want bool)
- func (i AssertableInertia) AssertComponent(want string)
- func (i AssertableInertia) AssertDeferredProps(want map[string][]string)
- func (i AssertableInertia) AssertEncryptHistory(want bool)
- func (i AssertableInertia) AssertMergeProps(want []string)
- func (i AssertableInertia) AssertProps(want Props)
- func (i AssertableInertia) AssertURL(want string)
- func (i AssertableInertia) AssertVersion(want string)
- type DeferProp
- type FlashProvider
- type Inertia
- func New(rootTemplateHTML string, opts ...Option) (*Inertia, error)
- func NewFromBytes(rootTemplateBs []byte, opts ...Option) (*Inertia, error)
- func NewFromFile(rootTemplatePath string, opts ...Option) (*Inertia, error)
- func NewFromReader(rootTemplateReader io.Reader, opts ...Option) (*Inertia, error)
- func NewFromTemplate(rootTemplate *template.Template, opts ...Option) (*Inertia, error)
- func (i *Inertia) Back(w http.ResponseWriter, r *http.Request, status ...int)
- 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) Redirect(w http.ResponseWriter, r *http.Request, url string, status ...int)
- 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) error
- func (i *Inertia) SharedProp(key string) (any, bool)
- func (i *Inertia) SharedProps() Props
- type JSONMarshaller
- type LazyPropdeprecated
- func Lazy(value any) LazyPropdeprecated
- type Logger
- type MergeProps
- type Option
- func WithContainerID(id string) Option
- func WithEncryptHistory(encryptHistory ...bool) Option
- func WithFlashProvider(flash FlashProvider) Option
- func WithJSONMarshaller(jsonMarshaller JSONMarshaller) Option
- func WithLogger(logs ...Logger) Option
- func WithSSR(url ...string) Option
- func WithVersion(version string) Option
- func WithVersionFromFile(path string) Option
- type OptionalProp
- type Proper
- type Props
- type TemplateData
- type TemplateFuncs
- type TryProper
- type ValidationErrors
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddValidationErrors ¶ added in v1.3.0
func AddValidationErrors(ctx context.Context, errors ValidationErrors) context.Context
AddValidationErrors appends validation errors to the passed context.
func ClearHistory ¶ added in v1.3.5
ClearHistory cleaning history state.
func ClearHistoryFromContext ¶ added in v1.3.5
ClearHistoryFromContext returns clear history value from the context.
func EncryptHistoryFromContext ¶ added in v1.3.5
EncryptHistoryFromContext returns history encryption value from the context.
func IsInertiaRequest ¶
IsInertiaRequest returns true if the request is an Inertia request.
func SetEncryptHistory ¶ added in v1.3.5
SetEncryptHistory enables or disables history encryption.
func SetTemplateData ¶ added in v1.3.0
func SetTemplateData(ctx context.Context, templateData TemplateData) context.Context
SetTemplateData sets template data to the passed context.
func SetTemplateDatum ¶ added in v1.3.0
SetTemplateDatum sets single template data item to the passed context.
func SetValidationError ¶ added in v1.3.0
SetValidationError sets validation error to the passed context.
func SetValidationErrors ¶ added in v1.3.0
func SetValidationErrors(ctx context.Context, errors ValidationErrors) context.Context
SetValidationErrors sets validation errors to the passed context.
Types ¶
type AlwaysProp ¶ added in v1.0.7
type AlwaysProp struct {
Value any
}
AlwaysProp is a property that will always evaluated.
https://inertiajs.com/partial-reloads
func Always ¶ added in v1.3.5
func Always(value any) AlwaysProp
func (AlwaysProp) Prop ¶ added in v1.1.5
func (p AlwaysProp) Prop() any
type AssertableInertia ¶ added in v1.0.2
AssertableInertia is an Inertia response struct with assert methods.
func AssertFromBytes ¶ added in v1.0.4
func AssertFromBytes(t t, body []byte) AssertableInertia
AssertFromBytes creates AssertableInertia from the bytes body.
func AssertFromReader ¶ added in v1.3.0
func AssertFromReader(t t, body io.Reader) AssertableInertia
AssertFromReader creates AssertableInertia from the io.Reader body.
func AssertFromString ¶ added in v1.0.4
func AssertFromString(t t, body string) AssertableInertia
AssertFromString creates AssertableInertia from the string body.
func (AssertableInertia) AssertClearHistory ¶ added in v1.3.5
func (i AssertableInertia) AssertClearHistory(want bool)
AssertClearHistory verifies that clear history value from Inertia response and the passed value are the same.
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) AssertDeferredProps ¶ added in v1.3.5
func (i AssertableInertia) AssertDeferredProps(want map[string][]string)
AssertDeferredProps verifies that deferred props from Inertia response and the passed deferred props are the same.
func (AssertableInertia) AssertEncryptHistory ¶ added in v1.3.5
func (i AssertableInertia) AssertEncryptHistory(want bool)
AssertEncryptHistory verifies that encrypt history value from Inertia response and the passed value are the same.
func (AssertableInertia) AssertMergeProps ¶ added in v1.3.5
func (i AssertableInertia) AssertMergeProps(want []string)
AssertMergeProps verifies that merge props from Inertia response and the passed merge props 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 FlashProvider ¶ added in v1.1.8
type FlashProvider interface { FlashErrors(ctx context.Context, errors ValidationErrors) error GetErrors(ctx context.Context) (ValidationErrors, error) ShouldClearHistory(ctx context.Context) (bool, error) FlashClearHistory(ctx context.Context) error }
FlashProvider defines an interface for a flash data provider.
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 NewFromBytes ¶ added in v1.1.4
NewFromBytes receive bytes with root template html and then initializes Inertia.
func NewFromFile ¶ added in v1.1.3
NewFromFile reads all bytes from the root template file and then initializes Inertia.
func NewFromReader ¶ added in v1.1.4
NewFromReader reads all bytes from the reader with root template html and then initializes Inertia.
func NewFromTemplate ¶ added in v1.3.5
NewFromTemplate receives a *template.Template and then initializes Inertia.
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.
If SSR is enabled, pre-renders JavaScript and return HTML (https://inertiajs.com/server-side-rendering).
func (*Inertia) ShareTemplateData ¶
ShareTemplateData adds passed data to shared template data.
func (*Inertia) ShareTemplateFunc ¶
ShareTemplateFunc adds the passed value to the shared template func map. If no root template HTML string has been defined, it returns an error.
func (*Inertia) SharedProp ¶
SharedProp return the shared prop.
func (*Inertia) SharedProps ¶
SharedProps returns shared props.
type JSONMarshaller ¶ added in v1.1.6
JSONMarshaller is marshaller which use for marshal/unmarshal JSON.
type LazyProp
deprecated
type LazyProp = OptionalProp
Deprecated: use OptionalProp.
type MergeProps ¶ added in v1.3.5
type MergeProps struct { Value any // contains filtered or unexported fields }
MergeProps is a property, which items will be merged instead of overwrite.
https://v2.inertiajs.com/merging-props
func Merge ¶ added in v1.3.5
func Merge(value any) MergeProps
func (MergeProps) Merge ¶ added in v1.3.5
func (p MergeProps) Merge() MergeProps
func (MergeProps) Prop ¶ added in v1.3.5
func (p MergeProps) Prop() any
type Option ¶
Option is an option parameter that modifies Inertia.
func WithContainerID ¶
WithContainerID returns Option that will set Inertia's container id.
func WithEncryptHistory ¶ added in v1.3.5
WithEncryptHistory returns Option that will enable Inertia's global history encryption.
func WithFlashProvider ¶ added in v1.1.8
func WithFlashProvider(flash FlashProvider) Option
WithFlashProvider returns Option that will set Inertia's flash data provider.
func WithJSONMarshaller ¶ added in v1.1.6
func WithJSONMarshaller(jsonMarshaller JSONMarshaller) Option
WithJSONMarshaller returns Option that will set Inertia's JSON marshaller.
func WithLogger ¶
WithLogger returns Option that will set Inertia's logger.
func WithSSR ¶ added in v1.1.0
WithSSR returns Option that will enable server side rendering on Inertia.
func WithVersion ¶
WithVersion returns Option that will set Inertia's version.
func WithVersionFromFile ¶ added in v1.1.0
WithVersionFromFile returns Option that will set Inertia's version based on file checksum.
type OptionalProp ¶ added in v1.3.5
type OptionalProp struct { Value any // contains filtered or unexported fields }
OptionalProp is a property that will evaluate when needed.
https://inertiajs.com/partial-reloads
func Optional ¶ added in v1.3.5
func Optional(value any) OptionalProp
func (OptionalProp) Prop ¶ added in v1.3.5
func (p OptionalProp) Prop() any
type Proper ¶ added in v1.1.5
type Proper interface {
Prop() any
}
Proper is an interface for custom type, which provides property, that will be resolved.
type Props ¶
Props are the data that will be transferred and will be available in the front-end component.
func PropsFromContext ¶ added in v1.0.5
PropsFromContext returns props from the context.
type TemplateData ¶
TemplateData are data that will be available in the root template.
func TemplateDataFromContext ¶ added in v1.0.5
func TemplateDataFromContext(ctx context.Context) TemplateData
TemplateDataFromContext returns template data from the context.
type TemplateFuncs ¶ added in v1.1.0
TemplateFuncs are functions that will be available in the root template.
type TryProper ¶ added in v1.1.5
TryProper is an interface for custom type, which provides property and error, that will be resolved.
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
ValidationErrorsFromContext returns validation errors from the context.