Description
Hello!
I've been experimenting these past 2 weeks on my spare time, trying to expose a runCode
global at the frontend, that will allow users to run arbitrary Go code, purely on the client side, it is heavily inspired by the gopher playground.
I removed the UI parts, and made some modifications, but I seem to be hitting a roadblock,
when trying to use
runCode(`
package main
import (
"fmt"
"syscall/js"
)
func main() {
fmt.Println("Hello, playground")
js.Global().Call("alert", "Hello, JavaScript")
js.Global().Get("console").Call("log", "Hello, JS console")
}
`)
I end up getting
$mapIndex is not defined
this error originates from fmt.Println
function only, other fmt functions I've tested work as expected.
Also, I've noticed that in the original code, there's a loading phase first, and then a run, it seems necessary in my case too, (running the code seems to be doing the loading phase + running, which throws some errors, but running again, will just run the code without loading, and result with no console errors) I'm just not sure as to how to implement it.
the altered code can be found here https://github.com/naorzr/gopherjs-runtime/blob/master/playground/main.go
and it can be run and played with by running the index.html
from this repo
https://github.com/naorzr/gopherjs-runtime/tree/master/playground