hello

command
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: BSD-3-Clause Imports: 1 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.

README

NAME

hello - run Go in Browser using WebAssembly

DESCRIPTION

Hello demonstrates running Go code in a browser using WebAssembly (instructions).

  1. write a Go program to do work in a main() function.
  2. build it into WebAssembly (Wasm):
    env GOOS=js GOARCH=wasm go build -o hello.wasm .
    
  3. 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>
    
  4. 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

Documentation

Overview

Hello demonstrates running Go in a browser using WebAssembly.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL