Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/eznix86/fiber-inertia

This is a Inertia.js server-side adapter based on inertia-laravel, but for Fiber Framework.
https://github.com/eznix86/fiber-inertia

Last synced: 3 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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
```go
app := fiber.New()
// AssetsPath is the path of your assets
app.Use(inertia.New(inertia.Config{
AssetsPath: "./public",
}))
```
- Use `Render` method

```go
inertia.Render(c,
"App",
inertia.Map{
"Hello" : "World",
},
)
```
#### Install Client Side

Use [official documentation](https://inertiajs.com/client-side-setup) to install client side.

#### Example:

```go
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",
},
)
}

```