I've been coding for several years now, and I've always been interested in "SPEED". Golang was among the elitists, so I've tried it out.
I've spent a few weeks to get some gist of it; through data structures and algorithms, thanks to Jon Calhoun courses.
And now is the time to shine!
How it started
A few months ago, I came across a package in PHP, mostly used in Laravel Framework, it is called InertiaJS.
In simple words, InertiaJS helps people to build a Single Page Application (SPA) without the intermediary of an API. Thus, we skip the authentication part (with JWT, or OAuth) and we focus only on sending the data to the particular component.
Under the hood
On a par with Server Side Rendering, this approach uses the same concept. When the page is loaded on the client, the data is baked into the HTML and rendered. The only difference here is that the page is a SPA, and InertiaJS pick up the data and enable you to rearrange your UI to your liking with VueJS, ReactJS, and Svelte, and all of that without building additional APIs. How cool is that?
Now that I've tried Golang, I wanted to evaluate myself, and InertiaJS had what I needed.
When hopping into InertiaJS, I've noticed that it some adapters: official ones, and Community ones, I've tried the Laravel one, and the Symfony's version also... But there was one missing, an adapter for Golang.
There was a fascinating thing they left for us, it was the protocol of InertiaJS. It was just a game of headers, and this helped me to get started.
Things are now in motion and cannot be undone.
I've started the project, it is a work-in-progress. But it works! 😊
First off, It doesn't work straight forward with Golang, it requires a framework so that it is easily implemented.
As a speed freak, it was an easy choice, so I've chosen GoFiber, for a couple of reasons:
- Speed, it was based on FastHTTP based on this benchmark, it was among the fastest.
- GoFiber is a Framework built on top of FastHTTP.
- I've used NodeJS few years ago, and GoFiber is an Express inspired web framework. (... nostalgia)
So without further ado;
Here is my project: https://github.com/theArtechnology/fiber-inertia
So far, my Golang module contains a GoFiber Middleware, and a GoFiber Render Function.
- Middleware; right now, we only intercept requests and calculate a hash for assets, enabling InertiaJS, so do its magic.
- Render Function; it is based on GoFiber Render Function, except is render a simple div, with an attribute containing some serialized data.
Once those and set up, you can directly head to InertiaJS webpage, and configure the client-side of the app.
And everything is magic....
This blog post is not yet done, as I said, things are in motion, and pull request are accepted 😎 .