inertia

package module
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2023 License: MIT Imports: 16 Imported by: 0

README

Inertia.js Go Adapter

The Inertia.js server-side adapter for Go. Visit inertiajs.com to learn more.


This packet uses Vite instead of Laravel Mix.

Original Source Code from here: https://github.com/elipZis/inertia-echo.
Stripped off everything except LICENSE.

License

This open-sourced software is licensed under the MIT license.

Documentation

Index

Constants

View Source
const HeaderLocation = HeaderPrefix + "-Location"
View Source
const HeaderPartialData = HeaderPrefix + "-Partial-Data"
View Source
const HeaderPrefix = "X-Inertia"

The Base "X-Inertia" header prefixes

View Source
const HeaderVersion = HeaderPrefix + "-Version"

Variables

View Source
var DefaultHTTPErrorHandler = func(err error, c echo.Context) {
	code := http.StatusInternalServerError
	if he, ok := err.(*echo.HTTPError); ok {
		code = he.Code
	}
	_ = c.Render(code, "Error", map[string]interface{}{
		"status": code,
	})
}

Functions

func Middleware

func Middleware(echo *echo.Echo) echo.MiddlewareFunc

Create a default Inertia Middleware for the given echo reference if the Inertia instance itself is not required in other instances

func MiddlewareWithConfig

func MiddlewareWithConfig(config MiddlewareConfig) echo.MiddlewareFunc

The Inertia Middleware to check every request for what it needs

Types

type Inertia

type Inertia struct {
	// contains filtered or unexported fields
}

func NewInertia

func NewInertia(echo *echo.Echo) (i *Inertia)

Instance a new Inertia Handler with a default config

func NewInertiaWithConfig

func NewInertiaWithConfig(config InertiaConfig) (i *Inertia)

Instance a new Inertia Handler with a configuration

func (*Inertia) GetShared

func (i *Inertia) GetShared(c echo.Context, key string) (interface{}, bool)

Get a specific key-value from the shared information

func (*Inertia) GetVersion

func (i *Inertia) GetVersion() string

func (*Inertia) Render

func (i *Inertia) Render(w io.Writer, name string, data interface{}, c echo.Context) error

Render renders a template document

func (*Inertia) SetVersion

func (i *Inertia) SetVersion(version string)

Set a version string

func (*Inertia) SetViteVersion

func (i *Inertia) SetViteVersion(viteManifestPath ...string) bool

Create a version hash off of the manifest.json file md5

func (*Inertia) Share

func (i *Inertia) Share(c echo.Context, key string, value interface{})

Share a key/value pairs with every response

func (*Inertia) Shared

func (i *Inertia) Shared(c echo.Context) map[string]interface{}

Returns the shared props (if any) and deletes them

func (*Inertia) Shares

func (i *Inertia) Shares(c echo.Context, values map[string]interface{})

Share multiple key/values with every response

func (*Inertia) Version

func (i *Inertia) Version(version func() string)

Set a version callback "func() string"

type InertiaConfig

type InertiaConfig struct {
	Echo *echo.Echo

	PublicPath       string
	TemplatesPath    string
	RootView         string
	TemplateFuncMap  template.FuncMap
	HTTPErrorHandler echo.HTTPErrorHandler
	RequestIDConfig  middleware.RequestIDConfig
}

func NewDefaultInertiaConfig

func NewDefaultInertiaConfig(e *echo.Echo) (i InertiaConfig)

Create a default Inertia Config to use without the hassle of setting up everything

type MiddlewareConfig

type MiddlewareConfig struct {
	Inertia *Inertia
	Skipper middleware.Skipper
}

type Response

type Response struct {
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse(component string, props map[string]interface{}, rootView string, version string) Response

func (Response) Status

func (r Response) Status(code int) Response

Allow to set a custom status

func (Response) ToResponse

func (r Response) ToResponse(c echo.Context) error

func (Response) With

func (r Response) With(key interface{}, value interface{}) Response

func (Response) WithViewData

func (r Response) WithViewData(key interface{}, value interface{}) Response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL