Skip to content

This is a Inertia.js server-side adapter based on inertia-laravel, but for Fiber Framework.

Notifications You must be signed in to change notification settings

eznix86/fiber-inertia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inertia.js Golang Adapter (Fiber)

This is a Inertia.js server-side adapter based on inertia-laravel, but for Fiber Framework.

Installation

go get -v github.com/theArtechnology/fiber-inertia

What do you need ?

  • Fiber Middleware
app := fiber.New()
// AssetsPath is the path of your assets
app.Use(inertia.New(inertia.Config{
	AssetsPath: "./public",
}))
  • Use Render method
inertia.Render(c,
	"App",
	inertia.Map{
	"Hello" : "World",
	},
)

Install Client Side

Use official documentation to install client side.

Example:

package main

import (
	"fmt"
	"github.com/gofiber/fiber"
	"github.com/gofiber/template/html"
	"github.com/theArtechnology/fiber-inertia/inertia"
	"log"
)

func main() {
	engine := html.New("./public", ".html")
	app := fiber.New(&fiber.Settings{
		Views: engine,
	})
	app.Static("/assets", "./public/build")

	app.Use(inertia.New(inertia.Config{
		AssetsPath: "./public",
	}))

	app.Get("/hi", hello)
	app.Get("/bonjour", world)
	fmt.Println("Server started")
	log.Fatal(app.Listen(3001))
}

func hello (c *fiber.Ctx) {
	inertia.Render(c,
		"Main", // Will render component named as Main
		inertia.Map{
		    "Hi-EN" : "Hello World",
		},
	)
}

func world (c *fiber.Ctx) {
	inertia.Render(c,
		"sub/Users", // Will render component in a subdirectory
		inertia.Map{
		    "Hi-FR" : "Bonjour tout le monde",
		},
	)
}

About

This is a Inertia.js server-side adapter based on inertia-laravel, but for Fiber Framework.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages