链接:https://pan.baidu.com/s/1-jwf-PsXh_JwnjgS7grdBw?pwd=19xn
将 wazero 嵌入您的项目中
Wazero 显然也是一个 Go 库,其主要目标是让您与运行时环境无缝集成,并使用 WebAssembly 扩展您的 Go 应用程序。例如,假设您想运行经典的 Unix 程序 cowsay[6](最初是用 Perl 编写的)。那么您可以输入:
// Download the executable from:
// https://github.com/evacchi/cowsay/releases/download/0.1.0/cowsay.wasm
//go:embed "cowsay.wasm"
var cowsay []byte
func main() {
ctx := context.Background()
r := wazero.NewRuntime(ctx)
wasi_snapshot_preview1.MustInstantiate(ctx, r)
r.InstantiateWithConfig(ctx, cowsay,
wazero.NewModuleConfig().
WithArgs("cowsay", // first arg is usually the executable name
"wazero is awesome!").
WithStdout(os.Stdout))
}