compileAndUploadTinygoWasm
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in miliseconds.
Make a Go program like so:
package main import ( "fmt" "net/http" gotown "github.com/maxmcd/go-town" ) func main() { gotown.ListenAndServe(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello World") })) }
Make sure you have tinygo (and optionally wasm-strip) installed. Then run this command with Deno to invoke this script:
deno run --allow-net --allow-run --allow-read \ "https://esm.town/v/maxm/compileAndUploadTinygoWasm?v=58"
That will print out the following:
Running tinygo build -o main.wasm -target=wasi . Compliation complete Running wasm-strip main.wasm Copy the following into a val town HTTP val: import { wasmHandler } from "https://esm.town/v/maxm/tinygoHttp"; const resp = await fetch("https://maxm-wasmBlobHost.web.val.run/jpxqvyy5tphiwehzklmioklpkpz4gpzs.wasm"); const handler = await wasmHandler(new Uint8Array(await resp.arrayBuffer())); export default async function(req: Request): Promise<Response> { return handler(req); }
Copy that into a Val and you have a working Go http handler! View that example here: https://www.val.town/v/maxm/crimsonMacaw
Migrated from folder: wasm/compileAndUploadTinygoWasm