2023-04-30 11:52:54 +09:00
|
|
|
# worker-template-tinygo
|
|
|
|
|
|
|
|
- A template for starting a Cloudflare Worker project with tinygo.
|
|
|
|
- This template uses [`workers`](https://github.com/syumai/workers) package to run an HTTP server.
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
- `main.go` includes simple HTTP server implementation. Feel free to edit this code and implement your own HTTP server.
|
|
|
|
|
|
|
|
## Requirements
|
|
|
|
|
|
|
|
- Node.js
|
|
|
|
- [wrangler](https://developers.cloudflare.com/workers/wrangler/)
|
|
|
|
- just run `npm install -g wrangler`
|
|
|
|
- tinygo
|
|
|
|
|
|
|
|
## Getting Started
|
|
|
|
|
2023-04-30 12:18:47 +09:00
|
|
|
```console
|
|
|
|
wrangler generate my-app syumai/workers/_templates/cloudflare/worker-tinygo
|
|
|
|
cd my-app
|
|
|
|
go mod init
|
|
|
|
go mod tidy
|
|
|
|
make dev # start running dev server
|
|
|
|
curl http://localhost:8787/hello # outputs "Hello!"
|
2023-04-30 11:52:54 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
- To change worker name, please edit `name` property in `wrangler.toml`.
|
|
|
|
|
|
|
|
## Development
|
|
|
|
|
|
|
|
### Commands
|
|
|
|
|
|
|
|
```
|
|
|
|
make dev # run dev server
|
|
|
|
make build # build Go Wasm binary
|
2023-05-21 11:56:31 +09:00
|
|
|
make deploy # deploy worker
|
2023-04-30 11:52:54 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
### Testing dev server
|
|
|
|
|
|
|
|
- Just send HTTP request using some tools like curl.
|
|
|
|
|
|
|
|
```
|
|
|
|
$ curl http://localhost:8787/hello
|
|
|
|
Hello!
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
$ curl -X POST -d "test message" http://localhost:8787/echo
|
|
|
|
test message
|
|
|
|
```
|