https://github.com/tiborhercz/go-wasm-example
Simple Go WASM example
https://github.com/tiborhercz/go-wasm-example
example go wasm webassembly
Last synced: about 7 hours ago
JSON representation
Simple Go WASM example
- Host: GitHub
- URL: https://github.com/tiborhercz/go-wasm-example
- Owner: tiborhercz
- Created: 2022-04-07T08:32:55.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-04-02T20:31:48.000Z (almost 3 years ago)
- Last Synced: 2025-10-09T08:14:56.110Z (4 months ago)
- Topics: example, go, wasm, webassembly
- Language: HTML
- Homepage: https://tiborhercz.com/golang-webassembly/
- Size: 6.84 KB
- Stars: 13
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go WebAssembly Example
Here you will find a simple Go WebAssembly Example. Showing you how to use Go to compile a `.wasm` file and run Go functions in the browser. Do you want more detail [read my Blog here](https://tiborhercz.com/golang-webassembly/)
In this example a SHA512 hash is created with WebAssembly using the value from the input field found in the HTML.
## How to run it
Compile the `.wasm` file
```shell
GOOS=js GOARCH=wasm go build -o static/main.wasm cmd/wasm/main.go
```
Copy the supporting JavaScript file
```shell
cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" ./static
```
Start the webserver
```shell
go run ./cmd/webserver/main.go
```
Navigate to: [http://localhost:3000/index.html](http://localhost:3000/index.html)
Here you will find an input field, which hashes the text with a SHA512 hash using the Go WebAssembly code. Found in `cmd/wasm/main.go`