Struct File Mapper uses Filesystem in Userspace feature in Linux systems to map in-memory data (user struct) to accessible file system.
- Get the package:
go get github.com/IslamWalid/struct_file_mapper
- Functionality:
Function | Description |
---|---|
func Mount(mountPointPath string, structReference any) error |
Creates a filesystem and mounts it to the given mount point path. |
func Unmount(mountPointPath string) error |
Unmount the filesystem in the given mount point path. |
NOTE: Unmount the filesystem after using it using the Umount
function, or through the command:
fusermount -u <mount_point_path>
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
sfmapper "github.com/IslamWalid/struct_file_mapper"
)
type Person struct {
Name string
Age int
}
func main() {
p := &Person{
Name: "Islam",
Age: 22,
}
// Create signal to recieve ctrl+c
sigs := make(chan os.Signal)
signal.Notify(sigs, syscall.SIGINT)
go func() {
<- sigs
sfmapper.UnMount("person")
}()
// Create directory person to host the filesystem
os.MkdirAll("person", 0777)
// Start the filesystem
err := sfmapper.Mount("person", p)
if err != nil {
fmt.Fprint(os.Stderr, err)
os.Exit(1)
}
}
NOTE: Arrays and slices are not supported.