Discover Packages
github.com/skhal/lab
x
wasm
hello
command
Version:
v0.1.0
Opens a new window with list of versions in this module.
Published: Sep 24, 2026
License: BSD-3-Clause
Opens a new window with license information.
Imports: 1
Opens a new window with list of imports.
Imported by: 0 modules, 0 packages
The first number is the count of modules that contain a package that imports this one.
The module count is a better indicator of popularity than the package count.
A module with 100 importing packages is counted only once instead of 100 times,
reflecting the fact that the choice to use the package was likely made only once,
not 100 times.
A '?' means that the value hasn't been computed yet.
Opens a new window with list of known importers.
README
README
¶
NAME
hello - run Go in Browser using WebAssembly
DESCRIPTION
Hello demonstrates running Go code in a browser using WebAssembly
(instructions ).
write a Go program to do work in a main() function.
build it into WebAssembly (Wasm):
env GOOS=js GOARCH=wasm go build -o hello.wasm .
Create an HTML page with following header:
<html>
<header>
<script src="wasm_exec.js"></script>
<script>
const go = new Go();
WebAssembly.instantiateStreaming(
fetch("hello.wasm"),
go.importObject,
).then((result) => {
go.run(result.instance);
});
</script>
</header>
</html>
open the page in a browser and check the console output.
It is important to use wasm_exec.js that comes with Go installation:
% ls `go env GOROOT`/lib/wasm
go_js_wasm_exec go_wasip1_wasm_exec wasm_exec.js wasm_exec_node.js
Alternatively, use make(1):
% make -C ./x/wasm/hello
% go run ./x/serve ./x/wasm/hello
Expand ▾
Collapse ▴
Documentation
¶
Hello demonstrates running Go in a browser using WebAssembly.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.