Fileb0x
a better customizable tool to embed files in go; also update embedded files remotely without restarting the server
Install / Use
/learn @UnnoTed/Fileb0xREADME
fileb0x

What is fileb0x?
A better customizable tool to embed files in go.
It is an alternative to go-bindata that have better features and organized configuration.
TL;DR
a better go-bindata
How does it compare to go-bindata?
Feature | fileb0x | go-bindata --------------------- | ------------- | ------------------ gofmt | yes (optional) | no golint | safe | unsafe gzip compression | yes | yes gzip decompression | yes (optional: runtime) | yes (on read) gzip compression levels | yes | no separated prefix / base for each file | yes | no (all files only) different build tags for each file | yes | no exclude / ignore files | yes (glob) | yes (regex) spread files | yes | no (single file only) unexported vars/funcs | yes (optional) | no virtual memory file system | yes | no http file system / handler | yes | no replace text in files | yes | no glob support | yes | no (walk folders only) regex support | no | yes (ignore files only) config file | yes (config file only) | no (cmd args only) update files remotely | yes | no
What are the benefits of using a Virtual Memory File System?
By using a virtual memory file system you can have access to files like when they're stored in a hard drive instead of a map[string][]byte you would be able to use IO writer and reader.
This means you can read, write, remove, stat and rename files also make, remove and stat directories.
TL;DR
Virtual Memory File System has similar functions as a hdd stored files would have.
Features
-
[x] golint safe code output
-
[x] optional: gzip compression (with optional run-time decompression)
-
[x] optional: formatted code (gofmt)
-
[x] optional: spread files
-
[x] optional: unexporTed variables, functions and types
-
[x] optional: include multiple files and folders
-
[x] optional: exclude files or/and folders
-
[x] optional: replace text in files
-
[x] optional: custom base and prefix path
-
[x] Virtual Memory FileSystem - webdav
-
[x] HTTP FileSystem and Handler
-
[x] glob support - doublestar
-
[x] json / yaml / toml support
-
[x] optional: Update files remotely
-
[x] optional: Build tags for each file
License
MIT
Get Started
TL;DR QuickStart™
Here's the get-you-going in 30 seconds or less:
git clone https://github.com/UnnoTed/fileb0x.git
cd fileb0x
cd _example/simple
go generate
go build
./simple
mod.godefines the package asexample.com/foo/simpleb0x.yamldefines the sub-packagestaticfrom the folderpublicmain.goincludes the comment//go:generate go run github.com/UnnoTed/fileb0x b0x.yamlmain.goalso includes the importexample.com/foo/simple/staticgo generatelocally installsfileb0xwhich generates./staticaccording tobax.yamlgo buildcreates the binarysimplefrompackage mainin the current folder./simpleruns the self-contained standalone webserver with built-in files frompublic
1. Download
go get -u github.com/UnnoTed/fileb0x
2. Create a config file
First you need to create a config file, it can be *.json, *.yaml or *.toml. (* means any file name)
Now write into the file the configuration you wish, you can use the example files as a start.
json config file example b0x.json
yaml config file example b0x.yaml
toml config file example b0x.toml
3. Run
if you prefer to use it from the cmd or terminal edit and run the command below.
fileb0x YOUR_CONFIG_FILE.yaml
or if you wish to generate the embedded files through go generate just add and edit the line below into your main.go.
//go:generate fileb0x YOUR_CONFIG_FILE.yaml
</details>
<details>
<summary>What functions and variables fileb0x let me access and what are they for?</summary>
HTTP
var HTTP http.FileSystem
Type
What is it?
A In-Memory HTTP File System.
What it does?
Serve files through a HTTP FileServer.
How to use it?
// http.ListenAndServe will create a server at the port 8080
// it will take http.FileServer() as a param
//
// http.FileServer() will use HTTP as a file system so all your files
// can be avialable through the port 8080
http.ListenAndServe(":8080", http.FileServer(myEmbeddedFiles.HTTP))
</details>
<details>
<summary>How to use it with `echo`?</summary>
package main
import (
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
// your embedded files import here ...
"github.com/UnnoTed/fileb0x/_example/echo/myEmbeddedFiles"
)
func main() {
e := echo.New()
// enable any filename to be loaded from in-memory file system
e.GET("/*", echo.WrapHandler(myEmbeddedFiles.Handler))
// http://localhost:1337/public/README.md
e.Start(":1337")
}
How to serve a single file through echo?
package main
import (
"github.com/labstack/echo"
// your embedded files import here ...
"github.com/UnnoTed/fileb0x/_example/echo/myEmbeddedFiles"
)
func main() {
e := echo.New()
// read ufo.html from in-memory file system
htmlb, err := myEmbeddedFiles.ReadFile("ufo.html")
if err != nil {
log.Fatal(err)
}
// convert to string
html := string(htmlb)
// serve ufo.html through "/"
e.GET("/", func(c echo.Context) error {
// serve as html
return c.HTML(http.StatusOK, html)
})
e.Start(":1337")
}
</details>
<details>
<summary>Examples</summary>
package main
import (
"log"
"net/http"
// your generaTed package
"github.com/UnnoTed/fileb0x/_example/simple/static"
)
func main() {
files, err := static.WalkDirs("", false)
if err != nil {
log.Fatal(err)
}
log.Println("ALL FILES", files)
// here we'll read the file from the virtual file system
b, err := static.ReadFile("public/README.md")
if err != nil {
log.Fatal(err)
}
// byte to str
s := string(b)
s += "#hello"
// write file back into the virtual file system
err := static.WriteFile("public/README.md", []byte(s), 0644)
if err != nil {
log.Fatal(err)
}
log.Println(string(b))
// true = handler
// false = file system
as := false
// try it -> http://localhost:1337/public/secrets.txt
if as {
// as Handler
panic(http.ListenAndServe(":1337", static.Handler))
} else {
// as File System
panic(http.ListenAndServe(":1337", http.FileServer(static.HTTP)))
}
}
</details>
<details>
<summary>Update files remotely</summary>
Having to upload an entire binary just to update some files in a b0x and restart a server isn't something that i like to do...
How it works?
By enabling the updater option, the next time that you generate a b0x, it will include a http server, this http server will use a http basic auth and it contains 1 endpoint / that accepts 2 methods: GET, POST.
The GET method responds with a list of file names and sha256 hash of each file.
The POST method is used to upload files, it creates the directory tree of a new file and then creates the file or it updates an existing file from the virtual memory file system... it responds with a ok string when the upload is successful.
How to update files remotely?
- First enable the updater option in your config file:
##################
## yaml example ##
##################
# updater allows you to update a b0x in a running server
# without having to restart it
updater:
# disabled by default
enabled: false
# empty mode creates a empty b0x file with just the
# server and the filesystem, then you'll have to upload
# the files later using the cmd:
# fileb0x -update=http://server.com:port b0x.yaml
#
# it avoids long compile time
empty: false
# amount of uploads at the same time
workers: 3
# to get a username and password from a env variable
# leave username and password blank (username: "")
# then set your username and password in the env vars
# (no caps) -> fileb0x_username and fileb0x_password
#
# when using env vars, set it before generating a b0x
# so it can be applied to the updater server.
username: "user" # username: ""
passwo
Related Skills
node-connect
337.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
337.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.2kCommit, push, and open a PR
