all: add support for the embed package

This commit is contained in:
Ayke van Laethem
2021-11-15 01:56:49 +01:00
committed by Ron Evans
parent fd20f63ee3
commit 87a4676137
12 changed files with 645 additions and 14 deletions
View File
+1
View File
@@ -0,0 +1 @@
bar
+1
View File
@@ -0,0 +1 @@
foo
+46
View File
@@ -0,0 +1,46 @@
package main
import (
"embed"
"strings"
)
//go:embed a hello.txt
var files embed.FS
var (
//go:embed "hello.*"
helloString string
//go:embed hello.txt
helloBytes []byte
)
// A test to check that hidden files are not included when matching a directory.
//go:embed a/b/.hidden
var hidden string
func main() {
println("string:", strings.TrimSpace(helloString))
println("bytes:", strings.TrimSpace(string(helloBytes)))
println("files:")
readFiles(".")
}
func readFiles(dir string) {
entries, err := files.ReadDir(dir)
if err != nil {
println(err.Error())
return
}
for _, entry := range entries {
entryPath := entry.Name()
if dir != "." {
entryPath = dir + "/" + entryPath
}
println("-", entryPath)
if entry.IsDir() {
readFiles(entryPath)
}
}
}
+1
View File
@@ -0,0 +1 @@
hello world!
+8
View File
@@ -0,0 +1,8 @@
string: hello world!
bytes: hello world!
files:
- a
- a/b
- a/b/bar.txt
- a/b/foo.txt
- hello.txt