I am trying to import a function from my golang WASM file to use in javascript but anytime i try and use the function i get a undefined error. But if i import my WASM file and then use the console i can manually call the function. I need to be able to call it within the js program. Thank's!
Browser Console Error
Uncaught ReferenceError: add is not defined
JS
async function init() {
const go = new Go();
const result = await WebAssembly.instantiateStreaming(
fetch("main.wasm"),
go.importObject
);
go.run(result.instance);
}
add("Hello")
init();
GOLANG
package main
import (
"fmt"
"syscall/js"
)
func add(this js.Value, inputs []js.Value) interface{} {
var input string = inputs[0].String()
return "you typed: " + input
}
func main() {
fmt.Println("hi")
js.Global().Set("add", js.FuncOf(add))
<-make(chan bool)
}