bigg01 / go-wasm-example

Simple Go WASM example

Home Page:https://tiborhercz.com/golang-webassembly/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

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

GOOS=js GOARCH=wasm go build -o static/main.wasm cmd/wasm/main.go

Copy the supporting JavaScript file

cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" ./static

Start the webserver

go run ./cmd/webserver/main.go

Navigate to: 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

About

Simple Go WASM example

https://tiborhercz.com/golang-webassembly/


Languages

Language:HTML 58.9%Language:Go 41.1%