Professional Documents
Culture Documents
(X) Running Go in The Browser With Web Assembly (WASM)
(X) Running Go in The Browser With Web Assembly (WASM)
(WASM)
If you are familiar with the Go Playground, then you know how convenient it is to be able
to have a Go scratchpad in the browser. Want to show someone a code snippet? Want to
quickly test some syntax? Browser-based code pads are helpful. On that note, I created a
new playground. The cool thing about this new playground that it doesn’t use a remote
server to run code, just to compile it. The code runs in your browser using web assembly
(WASM).
Update: There is now a sequel to this article outlining how we run the WASM inside Web
Workers which can be found here.
As you can see, the handler simply takes code as input and responds with a slice of
WASM bytes.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Boot.dev Classroom - Learn Coding</title>
</head>
<body>
<script src="wasm_exec.js"></script>
</body>
</html>
Because Boot.dev’s Classroom’s front-end is written as a Vue.js single page app, I’ve
created a small es6 module that runs a WASM byte array and returns the output as an
array of lines: