..
2023-05-29 18:48:09 -05:00
2024-01-03 00:43:21 +09:00
2023-11-07 22:14:23 +09:00
2023-05-29 18:48:09 -05:00
2024-01-03 23:34:03 +09:00
2023-11-07 22:28:43 +09:00
2023-05-29 18:48:09 -05:00

pages-tinygo

  • A template for starting a Cloudflare Pages Functions project with tinygo.
  • This template uses the workers package to run.

Usage

  • main.go includes a chi HTTP router implementation with three different routes. Feel free to edit this code and implement your own HTTP router.

Requirements

  • Node.js
  • wrangler
    • just run npm install -g wrangler
  • tinygo 0.29.0 or later

Getting Started

  • If not already installed, please install the gonew command.
go install golang.org/x/tools/cmd/gonew@latest
  • Create a new project using this template.
    • Second argument passed to gonew is a module path of your new app.
gonew github.com/syumai/workers/_templates/cloudflare/pages-tinygo your.module/my-app # e.g. github.com/syumai/my-app
cd my-app
go mod tidy
make build # build Go Wasm binary
make dev # start running dev server
curl http://localhost:8787/api/hello # outputs "Hello, Pages Functions!"

Development

Commands

make dev     # run dev server
make build   # build Go Wasm binary
make deploy # deploy worker

Testing dev server

  • You can send HTTP requests using tools like curl.
$ curl http://localhost:8787/api/hello
Hello, Pages Functions!
$ curl http://localhost:8787/api/hello?name=Example
Hello, Example!
$ curl http://localhost:8787/api/hello2
Hello, Hello world!
$ curl http://localhost:8787/api/hello3
Hello, Hello, Hello world!