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 NewFromFileFS(rootFS fs.FS, 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
- func WithVersionFromFileFS(rootFS fs.FS, 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 ¶
func AddValidationErrors(ctx context.Context, errors ValidationErrors) context.Context
AddValidationErrors appends validation errors to the passed context.
func ClearHistory ¶
ClearHistory cleaning history state.
func ClearHistoryFromContext ¶
ClearHistoryFromContext returns clear history value from the context.
func EncryptHistoryFromContext ¶
EncryptHistoryFromContext returns history encryption value from the context.
func IsInertiaRequest ¶
IsInertiaRequest returns true if the request is an Inertia request.
func SetEncryptHistory ¶
SetEncryptHistory enables or disables history encryption.
func SetTemplateData ¶
func SetTemplateData(ctx context.Context, templateData TemplateData) context.Context
SetTemplateData sets template data to the passed context.
func SetTemplateDatum ¶
SetTemplateDatum sets single template data item to the passed context.
func SetValidationError ¶
SetValidationError sets validation error to the passed context.
func SetValidationErrors ¶
func SetValidationErrors(ctx context.Context, errors ValidationErrors) context.Context
SetValidationErrors sets validation errors to the passed context.
Types ¶
type AlwaysProp ¶
type AlwaysProp struct {
Value any
}
AlwaysProp is a property that will always evaluated.
https://inertiajs.com/partial-reloads
func Always ¶
func Always(value any) AlwaysProp
func (AlwaysProp) Prop ¶
func (p AlwaysProp) Prop() any
type AssertableInertia ¶
AssertableInertia is an Inertia response struct with assert methods.
func AssertFromBytes ¶
func AssertFromBytes(t t, body []byte) AssertableInertia
AssertFromBytes creates AssertableInertia from the bytes body.
func AssertFromReader ¶
func AssertFromReader(t t, body io.Reader) AssertableInertia
AssertFromReader creates AssertableInertia from the io.Reader body.
func AssertFromString ¶
func AssertFromString(t t, body string) AssertableInertia
AssertFromString creates AssertableInertia from the string body.
func (AssertableInertia) AssertClearHistory ¶
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 ¶
func (i AssertableInertia) AssertComponent(want string)
AssertComponent verifies that component from Inertia response and the passed component are the same.
func (AssertableInertia) AssertDeferredProps ¶
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 ¶
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 ¶
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 ¶
func (i AssertableInertia) AssertProps(want Props)
AssertProps verifies that props from Inertia response and the passed props are the same.
func (AssertableInertia) AssertURL ¶
func (i AssertableInertia) AssertURL(want string)
AssertURL verifies that url from Inertia response and the passed url are the same.
func (AssertableInertia) AssertVersion ¶
func (i AssertableInertia) AssertVersion(want string)
AssertVersion verifies that version from Inertia response and the passed version are the same.
type FlashProvider ¶
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 ¶
NewFromBytes receive bytes with root template html and then initializes Inertia.
func NewFromFile ¶
NewFromFile reads all bytes from the root template file and then initializes Inertia.
func NewFromFileFS ¶
NewFromFileFS reads all bytes from the root template file and then initializes Inertia.
func NewFromReader ¶
NewFromReader reads all bytes from the reader with root template html and then initializes Inertia.
func NewFromTemplate ¶
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 ¶
JSONMarshaller is marshaller which use for marshal/unmarshal JSON.
type LazyProp
deprecated
type LazyProp = OptionalProp
Deprecated: use OptionalProp.
type MergeProps ¶
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 ¶
func Merge(value any) MergeProps
func (MergeProps) Merge ¶
func (p MergeProps) Merge() MergeProps
func (MergeProps) Prop ¶
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 ¶
WithEncryptHistory returns Option that will enable Inertia's global history encryption.
func WithFlashProvider ¶
func WithFlashProvider(flash FlashProvider) Option
WithFlashProvider returns Option that will set Inertia's flash data provider.
func WithJSONMarshaller ¶
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 WithVersion ¶
WithVersion returns Option that will set Inertia's version.
func WithVersionFromFile ¶
WithVersionFromFile returns Option that will set Inertia's version based on file checksum.
type OptionalProp ¶
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 ¶
func Optional(value any) OptionalProp
func (OptionalProp) Prop ¶
func (p OptionalProp) Prop() any
type Proper ¶
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 ¶
PropsFromContext returns props from the context.
type TemplateData ¶
TemplateData are data that will be available in the root template.
func TemplateDataFromContext ¶
func TemplateDataFromContext(ctx context.Context) TemplateData
TemplateDataFromContext returns template data from the context.
type TemplateFuncs ¶
TemplateFuncs are functions that will be available in the root template.
type TryProper ¶
TryProper is an interface for custom type, which provides property and error, that will be resolved.
type ValidationErrors ¶
ValidationErrors are messages, that will be stored in the "errors" prop.
func ValidationErrorsFromContext ¶
func ValidationErrorsFromContext(ctx context.Context) ValidationErrors
ValidationErrorsFromContext returns validation errors from the context.