Skip to content

Gopherjs runtime on frontend - inspired by gopherjs playground #76

Open
@naorzr

Description

@naorzr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions