Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions _examples/browser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public/build
node_modules
.wrangler
24 changes: 24 additions & 0 deletions _examples/browser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# browser example

* This example demonstrates running a Go HTTP server within the browser.
- It's just a static page.
* It showcases calculating the sum of two numbers, with the result rendered inside an iframe.

## Demo

* https://browser-example.syumai.workers.dev

## Requirements

- Node.js
- Go 1.24.0 or later

## Development

### Commands

```
make dev # run dev server
make build # build Go Wasm binary
make deploy # deploy static assets
```
7 changes: 7 additions & 0 deletions _examples/browser/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module github.com/syumai/workers/_examples/browser

go 1.24.0

require github.com/syumai/workers v0.0.0

replace github.com/syumai/workers => ../../
Empty file added _examples/browser/go.sum
Empty file.
29 changes: 29 additions & 0 deletions _examples/browser/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"encoding/json"
"net/http"

"github.com/syumai/workers"
)

type AddRequest struct {
A int `json:"a"`
B int `json:"b"`
}

func main() {
http.HandleFunc("POST /add", func(w http.ResponseWriter, req *http.Request) {
var addReq AddRequest
if err := json.NewDecoder(req.Body).Decode(&addReq); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
result := addReq.A + addReq.B
if err := json.NewEncoder(w).Encode(result); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
})
workers.Serve(nil)
}
Loading
Loading