Deploy a Go HTTP server in your browser
summary
Shows that a Go HTTP handler can run inside a browser by compiling to WebAssembly and wiring it into a ServiceWorker: registers a JS callback from Go via syscall/js, converts JS Request to a net/http Request using http.Test NewRequest and copies bodies with copyBytesToGo/copyBytesToJS, uses ResponseRecorder to capture handler output and returns a JS Response Promise. Demo serves an image-captioning form and a JSON hello API; it works but is slower and cannot host long‑running state because ServiceWorker lifecycle kills the WASM.
AI-written summary · about
chapters (16)
- 0:00Intro
- 2:21Build to WebAssembly
- 3:48Respond from a Service Worker
- 4:43Building a Go HTTP server
- 6:33The plan
- 7:38Adding is/wasm target server.go
- 8:45Implementing wasmhttp.Serve()
- 9:42Sending requests to Go sw.js
- 10:39Promise for a Response
- 11:58JS Request to Go Request
- 14:21Calling the HTTP Handler
- 15:59Go Response to JS Response
- 16:28Resolve Response Promise
- 16:43Sending back the Response sw.js
- 19:10JSON hello example Click the gopher!
- 21:00Catption example Click the gopher!
related talks
27m"WASM: Bringing Go to the Browser (and Beyond!)"
08mRunning Go in Browsers Using WASM
25mWebAssembly with Go: Powering the Web with Speed and Efficiency
29mExperimenting with Golang and Webassembly
18mGet Going With WebAssembly
24mWasm Workers Server: Portable Serverless Apps with WebAssembly
07mFirst Steps Into Web Server Development
27mService Workers + WebAssembly
