All Projects → petaki → inertia-go

petaki / inertia-go

Licence: MIT license
⏩ The Inertia.js server-side adapter for Go.

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to inertia-go

satellite
🛰️ Dashboard for probe.
Stars: ✭ 34 (-30.61%)
Mutual labels:  inertiajs
pingcrm-vite
⚡️ PingCRM on Vite Rails - A Vite.js + Inertia.js + Vue SSR + Rails demo
Stars: ✭ 48 (-2.04%)
Mutual labels:  inertiajs
Horizon
Building ChangeWindows one commit at a time
Stars: ✭ 31 (-36.73%)
Mutual labels:  inertiajs
yii2-inertia
The Yii 2 server-side adapter for Inertia.js.
Stars: ✭ 52 (+6.12%)
Mutual labels:  inertiajs
laravel-scaffold
Laravel + Inertia (Vue) + Tailwind Scaffold for new Projects
Stars: ✭ 33 (-32.65%)
Mutual labels:  inertiajs
atlas
Atlas: A React (Typescript), Laravel, Tailwind & Inertia starter kit. (Jetstream alternative)
Stars: ✭ 48 (-2.04%)
Mutual labels:  inertiajs
inertia
A preset for installing @inertiajs in a fresh Laravel project
Stars: ✭ 80 (+63.27%)
Mutual labels:  inertiajs
jetstream-inertia-generator
Laravel 8 Admin CRUD generator built with Jetstream, Inertia js, Vue 3 and Tailwindcss 2
Stars: ✭ 105 (+114.29%)
Mutual labels:  inertiajs
inertiajs-tables-laravel-query-builder
Inertia.js Tables for Laravel Query Builder
Stars: ✭ 391 (+697.96%)
Mutual labels:  inertiajs
inertia phoenix
Inertiajs Adapter for Elixir Phoenix
Stars: ✭ 60 (+22.45%)
Mutual labels:  inertiajs
pingcrm-yii2
Ping CRM on Yii 2 - A Yii 2 demo application to illustrate how Inertia.js works.
Stars: ✭ 39 (-20.41%)
Mutual labels:  inertiajs
RailsBooster
Pre-Configured Ruby On Rails Template To Provide Instant Productivity ⚡️
Stars: ✭ 22 (-55.1%)
Mutual labels:  inertiajs
pingcrm-mithril
Ping CRM on Mithril.js - A mithril demo application to illustrate how Inertia.js works.
Stars: ✭ 22 (-55.1%)
Mutual labels:  inertiajs

Inertia.js Go Adapter

Build Status License: MIT

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

Installation

Install the package using the go get command:

go get github.com/petaki/inertia-go

Usage

1. Create new instance

url := "http://inertia-app.test" // Application URL for redirect
rootTemplate := "./app.gohtml"   // Root template, see the example below
version := ""                    // Asset version

inertiaManager := inertia.New(url, rootTemplate, version)

Or create with embed.FS for root template:

import "embed"

//go:embed template
var templateFS embed.FS

// ...

inertiaManager := inertia.NewWithFS(url, rootTemplate, version, templateFS)

2. Register the middleware

mux := http.NewServeMux()
mux.Handle("/", inertiaManager.Middleware(homeHandler))

3. Render in handlers

func homeHandler(w http.ResponseWriter, r *http.Request) {
    // ...

    err := inertiaManager.Render(w, r, "home/Index", nil)
    if err != nil {
        // Handle server error...
    }
}

Or render with props:

// ...

err := inertiaManager.Render(w, r, "home/Index", map[string]interface{}{
    "total": 32,
})

//...

Examples

The following examples show how to use the package.

Share a prop globally

inertiaManager.Share("title", "Inertia App Title")

Share a function with root template

inertiaManager.ShareFunc("asset", assetFunc)
<script src="{{ asset "js/app.js" }}"></script>

Share a prop from middleware

func authenticate(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        // ...
        
        ctx := inertiaManager.WithProp(r.Context(), "authUserId", user.Id)
        next.ServeHTTP(w, r.WithContext(ctx))
    })
}

Share data with root template

ctx := inertiaManager.WithViewData(r.Context(), "meta", meta)
r = r.WithContext(ctx)
<meta name="description" content="{{ .meta }}">

Root template

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="css/app.css" rel="stylesheet">
        <link rel="icon" type="image/x-icon" href="favicon.ico">
    </head>
    <body>
        <div id="app" data-page="{{ marshal .page }}"></div>
        <script src="js/app.js"></script>
    </body>
</html>

Example Apps

Satellite

https://github.com/petaki/satellite

Homettp

https://github.com/homettp/homettp

Reporting Issues

If you are facing a problem with this package or found any bug, please open an issue on GitHub.

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].