Documentation
¶
Index ¶
- Constants
- Variables
- func IsPrecognition(c fiber.Ctx) bool
- func Redirect(c fiber.Ctx, url string) error
- func RedirectExternal(c fiber.Ctx, url string) error
- type AlwaysProp
- type CSRFTokenCheckProvider
- type CSRFTokenProvider
- type DeferredProp
- type Error
- type FiberSessionAdapter
- func (f *FiberSessionAdapter[T]) Delete(c fiber.Ctx, key string) error
- func (f *FiberSessionAdapter[T]) Flash(c fiber.Ctx, key string, value any) error
- func (f *FiberSessionAdapter[T]) Get(c fiber.Ctx, key string) (any, error)
- func (f *FiberSessionAdapter[T]) GetFlash(c fiber.Ctx, key string) (any, error)
- func (f *FiberSessionAdapter[T]) Set(c fiber.Ctx, key string, value any) error
- type FiberSessionStore
- type FlashError
- type FlashLevel
- type Inertia
- func (i *Inertia) DisableSSR()
- func (i *Inertia) EnableSSR(cfg SSRConfig)
- func (i *Inertia) EnableSSRWithDefault()
- func (i *Inertia) IsSSREnabled() bool
- func (i *Inertia) Middleware() fiber.Handler
- func (i *Inertia) MiddlewareErrorListener() fiber.ErrorHandler
- func (i *Inertia) ParseTemplates() error
- func (i *Inertia) Redirect(c fiber.Ctx, url string) error
- func (i *Inertia) RedirectBack(c fiber.Ctx) error
- func (i *Inertia) RedirectBackWithErrors(c fiber.Ctx, errors map[string]string) error
- func (i *Inertia) RedirectBackWithValidationErrors(c fiber.Ctx, errors ValidationErrors) error
- func (i *Inertia) RedirectExternal(c fiber.Ctx, url string) error
- func (i *Inertia) Render(c fiber.Ctx, component string, props map[string]any) error
- func (i *Inertia) WithClearHistory(c fiber.Ctx)
- func (i *Inertia) WithEncryptHistory(c fiber.Ctx)
- func (i *Inertia) WithError(c fiber.Ctx, field string, message string)
- func (i *Inertia) WithErrors(c fiber.Ctx, errors map[string]string)
- func (i *Inertia) WithFlash(c fiber.Ctx, key FlashLevel, message string)
- func (i *Inertia) WithFlashError(c fiber.Ctx, message string)
- func (i *Inertia) WithFlashInfo(c fiber.Ctx, message string)
- func (i *Inertia) WithFlashMessages(c fiber.Ctx, flashMessages ...FlashError)
- func (i *Inertia) WithFlashOld(c fiber.Ctx, data map[string]any)
- func (i *Inertia) WithFlashSuccess(c fiber.Ctx, message string)
- func (i *Inertia) WithFlashWarning(c fiber.Ctx, message string)
- func (i *Inertia) WithLazyProp(c fiber.Ctx, key string, fn func(context.Context) (any, error))
- func (i *Inertia) WithMatchPropsOn(c fiber.Ctx, props ...string)
- func (i *Inertia) WithProp(c fiber.Ctx, key string, value any)
- func (i *Inertia) WithValidationErrors(c fiber.Ctx, errors ValidationErrors)
- func (i *Inertia) WithViewData(c fiber.Ctx, key string, value any)
- type LazyProp
- type Logger
- type LoggerAdapter
- func (l *LoggerAdapter) DebugContext(ctx context.Context, msg string, args ...any)
- func (l *LoggerAdapter) ErrorContext(ctx context.Context, msg string, args ...any)
- func (l *LoggerAdapter) InfoContext(ctx context.Context, msg string, args ...any)
- func (l *LoggerAdapter) WarnContext(ctx context.Context, msg string, args ...any)
- type MergeProp
- type OnceOption
- type OnceProp
- type OncePropConfig
- type Option
- func WithAssetVersion(assetVersion string) Option
- func WithCSRFPropName(prop string) Option
- func WithCSRFTokenCheckProvider(provider CSRFTokenCheckProvider) Option
- func WithCSRFTokenProvider(provider CSRFTokenProvider) Option
- func WithCanExposeDetails(fn func(ctx context.Context, headers map[string][]string) bool) Option
- func WithCustomErrorDetailsHandler(fn func(errReturn *Error, isCanDetails bool) string) Option
- func WithCustomErrorGettingHandler(fn func(err error) *Error) Option
- func WithDevMode() Option
- func WithFS(fs fs.FS) Option
- func WithLogger(logger Logger) Option
- func WithPrecognitionVary(enabled bool) Option
- func WithPublicFS(fs fs.ReadFileFS) Option
- func WithRootErrorTemplate(rootErrorTemplate string) Option
- func WithRootHotTemplate(rootHotTemplate string) Option
- func WithRootTemplate(rootTemplate string) Option
- func WithSSRConfig(cfg SSRConfig) Option
- func WithSessionStore(sessionStore SessionStore) Option
- func WithSetSharedFuncMap(data template.FuncMap) Option
- func WithSharedProps(data map[string]any) Option
- func WithSharedViewData(data map[string]any) Option
- type OptionalProp
- type PageDTO
- type SSRClient
- type SSRConfig
- type ScrollProp
- type ScrollPropConfig
- type SessionAdapter
- type SessionStore
- type SsrDTO
- type ValidationError
- type ValidationErrors
Constants ¶
const ( // ContextKeyProps key. ContextKeyProps = contextKey("props") // ContextKeyViewData key. ContextKeyViewData = contextKey("viewData") // ContextKeyPageMeta key. ContextKeyPageMeta = contextKey("pageMeta") )
Context.
const ( // HeaderInertia header. HeaderInertia = "X-Inertia" // HeaderLocation header. HeaderLocation = "X-Inertia-Location" // HeaderVersion header. HeaderVersion = "X-Inertia-Version" // HeaderPartialComponent header. HeaderPartialComponent = "X-Inertia-Partial-Component" // HeaderPartialOnly header. HeaderPartialOnly = "X-Inertia-Partial-Data" // HeaderPartialExcept header. HeaderPartialExcept = "X-Inertia-Partial-Except" // HeaderReset header. HeaderReset = "X-Inertia-Reset" // HeaderErrorBag header. HeaderErrorBag = "X-Inertia-Error-Bag" // HeaderExceptOnceProps header. HeaderExceptOnceProps = "X-Inertia-Except-Once-Props" // HeaderInfiniteScrollMergeIntent header. HeaderInfiniteScrollMergeIntent = "X-Inertia-Infinite-Scroll-Merge-Intent" // HeaderPrecognition header. HeaderPrecognition = "Precognition" // HeaderPrecognitionValidateOnly header. HeaderPrecognitionValidateOnly = "Precognition-Validate-Only" // HeaderPrecognitionSuccess header. HeaderPrecognitionSuccess = "Precognition-Success" )
Header.
const ( ContextPropsErrors = "errors" ContextPropsOld = "old" ContextPropsFlash = "flash" ContextPropsCSRFToken = "csrf_token" )
Keys.
const ( DefaultSSRURL = "http://127.0.0.1:13714/render" DefaultSSRTimeout = 3 * time.Second DefaultCacheTTL = 5 * time.Minute DefaultCacheMaxEntries = 1024 DefaultSSRMaxRetries = 1 DefaultSSRRetryDelay = 10 * time.Millisecond )
Variables ¶
var ( // ErrInvalidContextViewData error. ErrInvalidContextViewData = errors.New("inertia: could not convert context view data to map") // ErrBadSsrStatusCode error. ErrBadSsrStatusCode = errors.New("inertia: bad processSSR status code >= 400") // ErrBaseURLEmpty error. ErrBaseURLEmpty = errors.New("base URL is empty") )
var ( ErrNillable = NewError(500, "inertia: value is nil") ErrInternal = NewError(fiber.StatusInternalServerError, utils.StatusMessage(fiber.StatusInternalServerError)) )
var ( DefaultCanExpose = func(_ context.Context, _ map[string][]string) bool { return false } DefaultCustomGettingError = func(_ error) *Error { return nil } DefaultCustomErrorDetails = func(appErr *Error, isCanDetails bool) string { details := "Something went wrong. Try again later" switch { case isCanDetails: details = appErr.Error() if errCause := appErr.Unwrap(); errCause != nil { if addDetailErr := errCause.Error(); addDetailErr != details { details += ": " + addDetailErr } } default: code := appErr.Code switch { case code == http.StatusBadRequest: details = "Bad request" case code == fiber.StatusNotFound: details = "Page not found" case code == fiber.StatusForbidden: details = "Permission denied" case code == fiber.StatusUnauthorized: details = "Unauthorized" case code == 419: details = "The page expired, please try again" case code == fiber.StatusTooManyRequests: details = "Too many request" case code >= http.StatusInternalServerError: details = "Something went wrong. Try again later" } } return details } )
Functions ¶
func IsPrecognition ¶ added in v0.9.4
Types ¶
type AlwaysProp ¶ added in v0.9.2
type AlwaysProp struct {
Value any
}
AlwaysProp marks a prop as always included, even on partial reloads.
func Always ¶ added in v0.9.2
func Always(value any) AlwaysProp
Always wraps a value as an always prop.
type CSRFTokenCheckProvider ¶
type DeferredProp ¶ added in v0.9.2
DeferredProp marks a prop as deferred (loaded via a follow-up partial reload).
func Defer ¶ added in v0.9.2
func Defer(value any, group ...string) DeferredProp
Defer wraps a value as a deferred prop. If group is empty, "default" is used.
type Error ¶
Error represents an error that occurred while handling a request.
func (*Error) CloneValidationError ¶
func (e *Error) CloneValidationError(err *ValidationError) *Error
func (*Error) FlashErrors ¶
func (e *Error) FlashErrors() []FlashError
func (*Error) ValidationErrors ¶
func (e *Error) ValidationErrors() ValidationErrors
func (*Error) WithFlashErrors ¶
func (e *Error) WithFlashErrors(errs ...*FlashError) *Error
type FiberSessionAdapter ¶
type FiberSessionAdapter[T FiberSessionStore] struct { // contains filtered or unexported fields }
func NewFiberSessionAdapter ¶
func NewFiberSessionAdapter[T FiberSessionStore](store SessionAdapter[T]) *FiberSessionAdapter[T]
func (*FiberSessionAdapter[T]) Delete ¶
func (f *FiberSessionAdapter[T]) Delete(c fiber.Ctx, key string) error
type FiberSessionStore ¶
type FlashError ¶
type FlashError struct {
Level FlashLevel
Message string
}
FlashError is a rich error that carries, UI message level and the user-facing message.
func NewFlashError ¶
func NewFlashError(level FlashLevel, userMessage string) *FlashError
NewFlashError creates a FlashError.
func (*FlashError) Error ¶
func (e *FlashError) Error() string
type FlashLevel ¶
type FlashLevel string
FlashLevel is a string enum for flash message level.
const ( FlashLevelSuccess FlashLevel = "success" FlashLevelInfo FlashLevel = "info" FlashLevelWarning FlashLevel = "warning" FlashLevelError FlashLevel = "error" )
func (FlashLevel) String ¶
func (f FlashLevel) String() string
type Inertia ¶
type Inertia struct {
// contains filtered or unexported fields
}
func New ¶
New init inertia
Example: optsInertia := []inertia.Option{inertia.WithFS(views.Templates)}
if cfg.Global.IsLocal() {
optsInertia = []inertia.Option{
inertia.WithRootTemplate("internal/adminext/views/app.gohtml"),
inertia.WithRootHotTemplate("internal/adminext/public/hot"),
inertia.WithFS(nil),
inertia.WithPublicFS(nil),
inertia.WithCanExposeDetails(func(c fiber.Ctx) bool {
admin := admin_middleware.GetAdminAuth(c)
return admin != nil && admin.HasRoles("admin")
}),
}
}
inertiaManager := inertia.New(cfg.Global.AppDomainURL, optsInertia...)
func NewWithValidation ¶ added in v0.9.1
func (*Inertia) DisableSSR ¶
func (i *Inertia) DisableSSR()
func (*Inertia) EnableSSRWithDefault ¶
func (i *Inertia) EnableSSRWithDefault()
func (*Inertia) IsSSREnabled ¶
func (*Inertia) MiddlewareErrorListener ¶
func (i *Inertia) MiddlewareErrorListener() fiber.ErrorHandler
func (*Inertia) ParseTemplates ¶ added in v0.9.1
func (*Inertia) RedirectBack ¶
RedirectBack redirects back to the previous page after a successful operation.
func (*Inertia) RedirectBackWithErrors ¶
RedirectBackWithErrors redirects back with validation errors stored in session.
func (*Inertia) RedirectBackWithValidationErrors ¶
func (i *Inertia) RedirectBackWithValidationErrors(c fiber.Ctx, errors ValidationErrors) error
RedirectBackWithValidationErrors redirects back with multiple validation errors per field.
func (*Inertia) RedirectExternal ¶ added in v0.9.2
RedirectExternal forces a full page reload for Inertia requests.
func (*Inertia) WithClearHistory ¶ added in v0.9.4
WithClearHistory sets clearHistory metadata for the response.
func (*Inertia) WithEncryptHistory ¶ added in v0.9.4
WithEncryptHistory sets encryptHistory metadata for the response.
func (*Inertia) WithErrors ¶
WithErrors adds validation errors to the response. Only adds to context; session is written via setFlashSessionData.
func (*Inertia) WithFlash ¶
func (i *Inertia) WithFlash(c fiber.Ctx, key FlashLevel, message string)
WithFlash adds flash message to the response. Only adds to context; session is written via setFlashSessionData.
func (*Inertia) WithFlashError ¶
WithFlashError adds error flash message.
func (*Inertia) WithFlashInfo ¶
WithFlashInfo adds info flash message.
func (*Inertia) WithFlashMessages ¶
func (i *Inertia) WithFlashMessages(c fiber.Ctx, flashMessages ...FlashError)
WithFlashMessages adds flashes messages.
func (*Inertia) WithFlashOld ¶
WithFlashOld adds flash message to the response. Only adds to context; session is written via setFlashSessionData.
func (*Inertia) WithFlashSuccess ¶
WithFlashSuccess adds success flash message.
func (*Inertia) WithFlashWarning ¶
WithFlashWarning adds warning flash message.
func (*Inertia) WithLazyProp ¶
WithLazyProp adds a lazy-evaluated prop that's only computed when requested.
func (*Inertia) WithMatchPropsOn ¶ added in v0.9.2
WithMatchPropsOn sets matchPropsOn metadata for the response.
func (*Inertia) WithValidationErrors ¶
func (i *Inertia) WithValidationErrors(c fiber.Ctx, errors ValidationErrors)
WithValidationErrors adds validation errors (equivalent to Django's form validation).
type LoggerAdapter ¶
type LoggerAdapter struct {
// contains filtered or unexported fields
}
func NewLoggerAdapter ¶
func NewLoggerAdapter(logger Logger) *LoggerAdapter
func (*LoggerAdapter) DebugContext ¶
func (l *LoggerAdapter) DebugContext(ctx context.Context, msg string, args ...any)
func (*LoggerAdapter) ErrorContext ¶
func (l *LoggerAdapter) ErrorContext(ctx context.Context, msg string, args ...any)
func (*LoggerAdapter) InfoContext ¶
func (l *LoggerAdapter) InfoContext(ctx context.Context, msg string, args ...any)
func (*LoggerAdapter) WarnContext ¶
func (l *LoggerAdapter) WarnContext(ctx context.Context, msg string, args ...any)
type MergeProp ¶ added in v0.9.2
MergeProp marks a prop as mergeable during partial reloads.
type OnceOption ¶ added in v0.9.2
type OnceOption func(*OnceProp)
OnceOption configures a OnceProp.
func WithOnceExpiresAt ¶ added in v0.9.2
func WithOnceExpiresAt(t time.Time) OnceOption
WithOnceExpiresAt sets an expiration time for a once prop.
func WithOnceKey ¶ added in v0.9.2
func WithOnceKey(key string) OnceOption
WithOnceKey sets a custom key for a once prop.
type OnceProp ¶ added in v0.9.2
OnceProp marks a prop as once and optionally sets expiration.
func Once ¶ added in v0.9.2
func Once(value any, opts ...OnceOption) OnceProp
Once wraps a value as a once prop.
type OncePropConfig ¶ added in v0.9.2
OncePropConfig defines a once prop configuration. ExpiresAt is a unix timestamp in milliseconds. Nil encodes as null.
type Option ¶
type Option func(*Inertia)
func WithAssetVersion ¶
func WithCSRFPropName ¶
WithCSRFPropName overrides the prop key used when injecting CSRF token.
func WithCSRFTokenCheckProvider ¶
func WithCSRFTokenCheckProvider(provider CSRFTokenCheckProvider) Option
WithCSRFTokenCheckProvider registers a resolver that check CSRF token into every rendered page.
func WithCSRFTokenProvider ¶
func WithCSRFTokenProvider(provider CSRFTokenProvider) Option
WithCSRFTokenProvider registers a resolver that injects CSRF token into every rendered page.
func WithCanExposeDetails ¶
WithCanExposeDetails sets a callback to decide if current request may see error details in production. Useful to allow main admins to see full error messages.
func WithCustomErrorDetailsHandler ¶
WithCustomErrorDetailsHandler sets a callback to handler error details.
func WithCustomErrorGettingHandler ¶
WithCustomErrorGettingHandler sets function callback for custom getting errors.
func WithDevMode ¶ added in v0.9.1
func WithDevMode() Option
WithDevMode enables development mode. In this mode, the Vite hot file is checked on every request, allowing for dynamic starts/restarts of the Vite server.
func WithLogger ¶
func WithPrecognitionVary ¶ added in v0.9.4
WithPrecognitionVary controls whether "Vary: Precognition" is added to Inertia responses. Defaults to true to match the protocol recommendation.
func WithPublicFS ¶
func WithPublicFS(fs fs.ReadFileFS) Option
func WithRootErrorTemplate ¶
func WithRootHotTemplate ¶
func WithRootTemplate ¶
func WithSSRConfig ¶
WithSSRConfig enables SSR with the provided config.
func WithSessionStore ¶
func WithSessionStore(sessionStore SessionStore) Option
func WithSetSharedFuncMap ¶
func WithSharedProps ¶
func WithSharedViewData ¶
type OptionalProp ¶ added in v0.9.2
type OptionalProp struct {
Value any
}
OptionalProp marks a prop as optional (only included when explicitly requested).
func Optional ¶ added in v0.9.2
func Optional(value any) OptionalProp
Optional wraps a value as an optional prop.
type PageDTO ¶
type PageDTO struct {
Component string `json:"component"`
Props map[string]any `json:"props"`
URL string `json:"url"`
Version string `json:"version"`
EncryptHistory bool `json:"encryptHistory,omitempty"`
ClearHistory bool `json:"clearHistory,omitempty"`
DeferredProps map[string][]string `json:"deferredProps,omitempty"`
MergeProps []string `json:"mergeProps,omitempty"`
PrependProps []string `json:"prependProps,omitempty"`
DeepMergeProps []string `json:"deepMergeProps,omitempty"`
MatchPropsOn []string `json:"matchPropsOn,omitempty"`
ScrollProps map[string]ScrollPropConfig `json:"scrollProps,omitempty"`
OnceProps map[string]OncePropConfig `json:"onceProps,omitempty"`
}
PageDTO type.
type ScrollProp ¶ added in v0.9.2
type ScrollProp struct {
Value any
Config ScrollPropConfig
}
ScrollProp marks a prop as an infinite-scroll prop and adds scroll metadata.
func Scroll ¶ added in v0.9.2
func Scroll(value any, cfg ScrollPropConfig) ScrollProp
Scroll wraps a value as a scroll prop with metadata.
type ScrollPropConfig ¶ added in v0.9.2
type ScrollPropConfig struct {
PageName string `json:"pageName,omitempty"`
PreviousPage any `json:"previousPage,omitempty"`
NextPage any `json:"nextPage,omitempty"`
CurrentPage any `json:"currentPage,omitempty"`
}
ScrollPropConfig defines pagination metadata for infinite scroll props.
type SessionAdapter ¶
type SessionAdapter[T FiberSessionStore] interface { Get(c fiber.Ctx) (T, error) }
type SessionStore ¶
type ValidationError ¶
type ValidationError struct {
// contains filtered or unexported fields
}
func NewValidationError ¶
func NewValidationError(code int, userMessage string, errs ValidationErrors) *ValidationError
NewValidationError creates a ValidationError.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) Errors ¶
func (e *ValidationError) Errors() ValidationErrors
type ValidationErrors ¶
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic-app
command
|
|
|
basic-app-react
command
|
|
|
basic-app-react-ssr
command
|
|
|
basic-app-ssr
command
|
|
|
Package goinertiamocks is a generated GoMock package.
|
Package goinertiamocks is a generated GoMock package. |