Documentation ¶
Index ¶
- func IsInertiaRequest(r *http.Request) bool
- func WithProp(ctx context.Context, key string, val any) context.Context
- func WithProps(ctx context.Context, props Props) context.Context
- func WithTemplateData(ctx context.Context, key string, val any) context.Context
- func WithValidationError(ctx context.Context, key string, msg any) context.Context
- func WithValidationErrors(ctx context.Context, errors ValidationErrors) context.Context
- type AlwaysProp
- type AssertableInertia
- 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 (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)
- func (i *Inertia) SharedProp(key string) (any, bool)
- func (i *Inertia) SharedProps() Props
- type JSONMarshaller
- type LazyProp
- type Logger
- type Option
- func WithContainerID(id string) Option
- func WithFlashProvider(flashData 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 Proper
- type Props
- type TemplateData
- type TemplateFuncs
- type TryProper
- 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.
func WithTemplateData ¶ added in v1.1.0
WithTemplateData appends template data value to the passed context.Context.
func WithValidationError ¶ added in v1.1.0
WithValidationError appends validation error to the passed context.Context.
func WithValidationErrors ¶ added in v1.1.0
func WithValidationErrors(ctx context.Context, errors ValidationErrors) context.Context
WithValidationErrors appends validation errors to the passed context.Context.
Types ¶
type AlwaysProp ¶ added in v1.0.7
type AlwaysProp struct {
Value any
}
AlwaysProp is a property value that will always evaluated.
https://github.com/inertiajs/inertia-laravel/pull/627
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 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 FlashProvider ¶ added in v1.1.8
type FlashProvider interface { FlashErrors(ctx context.Context, errors ValidationErrors) error GetErrors(ctx context.Context) (ValidationErrors, error) }
FlashProvider defines an interface for 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 (*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 passed value to the shared template func map.
func (*Inertia) SharedProp ¶
SharedProp return the shared prop.
func (*Inertia) SharedProps ¶
SharedProps returns shared props.
type JSONMarshaller ¶ added in v1.1.6
type JSONMarshaller interface { Marshal(v any) ([]byte, error) Decode(r io.Reader, v interface{}) error }
JSONMarshaller is marshaller which use for marshal/unmarshal JSON.
type LazyProp ¶
type LazyProp struct {
Value any
}
LazyProp is a property value that will only evaluated then needed.
type Option ¶
Option is an option parameter that modifies Inertia.
func WithContainerID ¶
WithContainerID returns Option that will set Inertia's container id.
func WithFlashProvider ¶ added in v1.1.8
func WithFlashProvider(flashData 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 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.
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, error)
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, error)
ValidationErrorsFromContext returns validation errors from the context.