github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/fsconfig_example_test.go (about)

     1  package wazero_test
     2  
     3  import (
     4  	"embed"
     5  	"io/fs"
     6  	"log"
     7  
     8  	"github.com/tetratelabs/wazero"
     9  )
    10  
    11  //go:embed testdata/index.html
    12  var testdataIndex embed.FS
    13  
    14  var moduleConfig wazero.ModuleConfig
    15  
    16  // This example shows how to configure an embed.FS.
    17  func Example_fsConfig() {
    18  	// Strip the embedded path testdata/
    19  	rooted, err := fs.Sub(testdataIndex, "testdata")
    20  	if err != nil {
    21  		log.Panicln(err)
    22  	}
    23  
    24  	moduleConfig = wazero.NewModuleConfig().
    25  		// Make "index.html" accessible to the guest as "/index.html".
    26  		WithFSConfig(wazero.NewFSConfig().WithFSMount(rooted, "/"))
    27  }