Skip to content

Instantly share code, notes, and snippets.

@timmattison
Created April 17, 2024 21:12
Show Gist options
  • Save timmattison/303bf203b054d25197ebd0c0112bca4e to your computer and use it in GitHub Desktop.
Save timmattison/303bf203b054d25197ebd0c0112bca4e to your computer and use it in GitHub Desktop.
Runs one of the Golang gioui samples as a locally hosted WASM application
#!/usr/bin/env bash
# This script is nothing crazy, it just wraps up the stuff I needed from https://gioui.org/doc/install/wasm so I can run things with a one-liner
if [ -z "$1" ]; then
echo "No sample specified, defaulting to kitchen"
SAMPLE="kitchen"
else
SAMPLE=$1
echo "Attempting to run $SAMPLE sample as a WASM application"
fi
cleanup() {
if [ -z "$bg_pid" ]; then
echo "No background process to kill"
return
fi
echo "Script exiting, killing background process... $bg_pid"
kill "$bg_pid"
}
trap cleanup EXIT
mkdir -p build/"$SAMPLE"
cd build/"$SAMPLE" || exit
go install gioui.org/cmd/gogio@latest
gogio -target js gioui.org/example/"$SAMPLE"
go install github.com/shurcooL/goexec@latest
go get github.com/shurcooL/go-goon
goexec "http.ListenAndServe(\":8080\", http.FileServer(http.Dir(\"$SAMPLE\")))" & bg_pid=$!
open http://localhost:8080
wait $bg_pid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment