Published
Edited
Jan 7, 2020
Fork of Go WASM
Insert cell
Insert cell
Insert cell
Insert cell
highlightRender(
'go',
`
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
`
)
Insert cell
Insert cell
highlightRender(
'sh',
`
GOOS=js GOARCH=wasm go build -o hello.wasm hello.go
`
)
Insert cell
Insert cell
helloWorld = async () => {
const { Go } = window;
const go = new Go();

const headers = new Headers();
headers.set('Content-Type', 'application/wasm');
const response = new Response(
await FileAttachment('query@3.wasm').arrayBuffer(),
{
headers: headers
}
);

WebAssembly.instantiateStreaming(response, go.importObject).then(result => {
go.run(result.instance);
});

console.log(FileAttachment('query@3.wasm'))
// WebAssembly.instantiate(
// await FileAttachment('query@3.wasm').arrayBuffer(),
// go.importObject
// ).then(result => {
// go.run(result.instance);
// });

return 'Done';
}
Insert cell
Insert cell
{
await loadWasmExec(() => {});
await helloWorld();
return 'Loaded';
}
Insert cell
loadWasmExec = async callback => {
const response = await fetch(
'https://raw.githubusercontent.com/golang/go/release-branch.go1.13/misc/wasm/wasm_exec.js'
);
const text = await response.text();

const script = document.createElement('script');
const code = document.createTextNode(text);
script.appendChild(code);
script.onload = callback;

document.body.appendChild(script);
}
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more