github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/testdata/embed/embed.go (about)

     1  package main
     2  
     3  import (
     4  	"embed"
     5  	"strings"
     6  )
     7  
     8  //go:embed a hello.txt
     9  var files embed.FS
    10  
    11  var (
    12  	//go:embed "hello.*"
    13  	helloString string
    14  
    15  	//go:embed hello.txt
    16  	helloBytes []byte
    17  )
    18  
    19  // A test to check that hidden files are not included when matching a directory.
    20  //go:embed a/b/.hidden
    21  var hidden string
    22  
    23  var helloStringBytes = []byte(helloString)
    24  
    25  func main() {
    26  	println("string:", strings.TrimSpace(helloString))
    27  	println("bytes:", strings.TrimSpace(string(helloBytes)))
    28  	println("[]byte(string):", strings.TrimSpace(string(helloStringBytes)))
    29  	println("files:")
    30  	readFiles(".")
    31  }
    32  
    33  func readFiles(dir string) {
    34  	entries, err := files.ReadDir(dir)
    35  	if err != nil {
    36  		println(err.Error())
    37  		return
    38  	}
    39  	for _, entry := range entries {
    40  		entryPath := entry.Name()
    41  		if dir != "." {
    42  			entryPath = dir + "/" + entryPath
    43  		}
    44  		println("-", entryPath)
    45  		if entry.IsDir() {
    46  			readFiles(entryPath)
    47  		}
    48  	}
    49  }