-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🚀 [Feature]: Unified binary support out of the box #394
Comments
I literally just finished playing with this while playing with combining Fiber and Hugo (and HTMX). Got it working in a few minutes after reading: https://dev.to/aryaprakasa/serving-single-page-application-in-a-single-binary-file-with-go-12ij#serve-with-fiber-framework. Note that it works as described for v2, but v3's change to remove filesystem and replace it with static had a side-effect that the static FS parameter won't accept an http.FS. I'm not a Go expert by any means... barely past beginner, so I just stayed with v2 for now. Would love to see this documented formally though, it's actually pretty cool. |
@idearat Can you open a ticket in https://github.com/gofiber/fiber, so we can look into that (http.FS) param. Thanks |
I actually also intended to create this issue at Anyway, I currently already switched to v3 (which is in beta) and would love to see an implementation which would let you include all types of assets into the binary. |
@the-hotmann You can use embed.FS with the new static middleware. //go:embed static.go config.go
var fsTestFilesystem embed.FS
app := fiber.New()
app.Get("/embed*", New("", static.Config{
FS: fsTestFilesystem,
Browse: true,
})) |
Ok it works. I have tried these two:
With It works, but how can I serve a native
But if you open a picture in a new tab, your browser will not load the favicon, as it now does not know where it is. Just if html is served the head-link can be set. Is there a workaround for this? Can files that are embedded also be served under the root-path? I am talking about this:
|
Ok, got it to work on Fiber v3 aswell:
Hope this helps. As I mentioned above: everything is a little "hacky" and it would be cool if all this would be more tightly integrated into fiber :) Now just the template embedding it missing |
Now I have figured out how to also include the html/templates:
I hope this helps someone. |
From my research golang doesnt support conditional embed. It's a compile time, not runtime feature. This limits how much we can do in Fiber. Will report back. |
Feature Description
I often create small Fiber apps, and I've been thinking about ways to make them easier to deploy and move around.
One of the main challenges I face is that certain files, like:
are not included in the statically compiled binary. If all these files could be bundled within the binary, it would significantly simplify deployment. A few considerations arise once these assets are included in the binary:
Can CSS files still be served compressed after inclusion?
If so, it would be ideal to compress all static files at startup and store them in cache.
I’ve reviewed the following discussions:
From these, I believe the templ package could be a good solution for embedding HTML templates into the binary. I also read this comment #302 (comment) but thought it was a bad example. It only demonstrated rendering static text without passing variables, using templates/partials, or including other static files (CSS, JS, icons). It also didn’t address whether those static assets can still be served compressed or cached.
While I'm not specifically set on templ, despite its increasing popularity, what I'd really like is a simple way to bundle HTML templates, CSS, JS, and other static files into the final statically compiled binary for Fiber apps.
I think this is something many developers would find useful. Ideally, it would be as simple as importing a Fiber sub-package or enabling the feature like this:
This way, all assets and templates would be included in the binary. I understand implementing this isn’t straightforward, but a possible approach could involve:
embed
package, orspf13/afero
.However, I'm not familiar with those libraries.
From what I've gathered from other discussions, it seems that some of these features might already be achievable. However, they wouldn’t work seamlessly with Fiber and would require a considerable amount of workaround to implement effectively.
I would love to have a discussion about and see if that is something the maintainers of fiber are considering beeing useful, or not.
This is not primarily about using templ. The main focus is on finding a easy straightforward way to include all assets - typically residing outside the statically compiled binary - into the binary itself.
Checklist:
The text was updated successfully, but these errors were encountered: