Skip to content

Instantly share code, notes, and snippets.

@ItalyPaleAle
Last active October 20, 2021 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ItalyPaleAle/4b83917d2ae561e23b9d071be710377f to your computer and use it in GitHub Desktop.
Save ItalyPaleAle/4b83917d2ae561e23b9d071be710377f to your computer and use it in GitHub Desktop.
// Copyright (C) 2020 Alessandro Segala (ItalyPaleAle)
// License: MIT
package main
// Import the package to access the Wasm environment
import (
"syscall/js"
)
// Main function: it sets up our Wasm application
func main() {
// Define the function "MyGoFunc" in the JavaScript scope
js.Global().Set("MyGoFunc", MyGoFunc())
// Prevent the function from returning, which is required in a wasm module
select {}
}
// MyGoFunc returns a JavaScript function
func MyGoFunc() js.Func {
return js.FuncOf(func(this js.Value, args []js.Value) interface{} {
// Return a JS dictionary with two keys (of heterogeneous type)
return map[string]interface{}{
"hello": "world",
"answer": 42,
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment