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:
1package main
2
3import (
4 "embed"
5 "fmt"
6)
7
8//go:embed files/*
9var content embed.FS
10
11func main() {
12 data, err := content.ReadFile("files/example.txt")
13 if err != nil {
14 fmt.Println("Error reading file:", err)
15 return
16 }
17
18 fmt.Println("File content:", string(data))
19}
20
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.