Options
All
  • Public
  • Public/Protected
  • All
Menu

go2js

Go2JS

Compile Go to JS in the browser (using GopherJS)

Based on GopherJS Playground

The motive for this project was to enable client-side compiling of Golang to JavaScript to run in the browser for LocalPen.

Usage

<script src="index.js"></script>
<script>
  const code = `
package main

import (
  "fmt"
  "syscall/js"
)

func main() {
  fmt.Println("Hello, from Go")
  js.Global().Call("alert", "Hello, JavaScript")
  println("Hello, JS console")
}
`;
  window.go2js.compile(code).then(eval).catch(console.warn);
</script>

Run npm start to start a server (http://127.0.0.1:8080) and watch for changes.

Contribution

Please do!

Feedback, ideas and pull requests are highly appreciated.

License

MIT

Support the author

ko-fi

Generated using TypeDoc