mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
all: add support for the embed package
This commit is contained in:
committed by
Ron Evans
parent
fd20f63ee3
commit
87a4676137
Vendored
Vendored
+1
@@ -0,0 +1 @@
|
||||
bar
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
foo
|
||||
Vendored
+46
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
hello world!
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
string: hello world!
|
||||
bytes: hello world!
|
||||
files:
|
||||
- a
|
||||
- a/b
|
||||
- a/b/bar.txt
|
||||
- a/b/foo.txt
|
||||
- hello.txt
|
||||
Reference in New Issue
Block a user