log / check file system when using go embed

We can check if the FS (File System) is successfully embedded by trying to access a file or directory from it. If there are no errors during compilation, it’s likely that the embedding process was successful.

For example, you can use a simple ReadFile operation to verify:

package main

import (
	"embed"
	"fmt"
)

//go:embed files/*
var content embed.FS

func main() {
	data, err := content.ReadFile("files/example.txt")
	if err != nil {
		fmt.Println("Error reading file:", err)
		return
	}

	fmt.Println("File content:", string(data))
}

Make sure the path provided to ReadFile matches the structure of the embedded files. If there are no errors during compilation and the program runs without issues, the FS is likely successfully embedded.

Written on 2024-01-11 02:58:00 +0700 Edited on 2024-03-11 03:52:00 +0700