Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use C3 for templates #157

Merged
merged 1 commit into from
Feb 23, 2025
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
41 changes: 32 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,48 @@ For concrete examples, see `_examples` directory.

## Quick Start

First, please install the following tools:
### Requirements

* Node.js (and npm)
* [wrangler](https://developers.cloudflare.com/workers/wrangler/)
- You can install it by running `npm install -g wrangler`.
* Go 1.24.0 or later
* [gonew](https://pkg.go.dev/golang.org/x/tools/cmd/gonew)
- You can install it by running `go install golang.org/x/tools/cmd/gonew@latest`

After installation, please run the following commands.
### Create a new Worker project

Run the following command:

```console
npm create cloudflare@latest -- --template github.com/syumai/workers/_templates/cloudflare/worker-go
```

### Initialize the project

1. Navigate to your new project directory:

```console
gonew github.com/syumai/workers/_templates/cloudflare/worker-go your.module/my-app # e.g. github.com/syumai/my-app
cd my-app
```

2. Initialize Go modules:

```console
go mod init
go mod tidy
make dev # start running dev server
curl http://localhost:8787/hello # outputs "Hello!"
```

3. Start the development server:

```console
npm start
```

4. Verify the worker is running:

```console
curl http://localhost:8787/hello
```

You will see **"Hello!"** as the response.

If you want a more detailed description, please refer to the README.md file in the generated directory.

## FAQ
Expand Down
12 changes: 0 additions & 12 deletions _templates/cloudflare/worker-go/Makefile

This file was deleted.

28 changes: 12 additions & 16 deletions _templates/cloudflare/worker-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

## Notice

- A free plan Cloudflare Workers only accepts ~1MB sized workers.
- Go Wasm binaries easily exceeds this limit, so **you'll need to use a paid plan of Cloudflare Workers** (which accepts ~5MB sized workers).
- Go (not TinyGo) with many dependencies may exceed the size limit of the Worker (3MB for free plan, 10MB for paid plan). In that case, you can use the [TinyGo template](https://github.com/syumai/workers/tree/main/_templates/cloudflare/worker-tinygo) instead.

## Usage

Expand All @@ -15,39 +14,36 @@
## Requirements

- Node.js
- [wrangler](https://developers.cloudflare.com/workers/wrangler/)
- just run `npm install -g wrangler`
- Go 1.21.0 or later
- Go 1.24.0 or later

## Getting Started

* If not already installed, please install the [gonew](https://pkg.go.dev/golang.org/x/tools/cmd/gonew) command.
- Create a new worker project using this template.

```console
go install golang.org/x/tools/cmd/gonew@latest
npm create cloudflare@latest -- --template github.com/syumai/workers/_templates/cloudflare/worker-go
```

* Create a new project using this template.
- Second argument passed to `gonew` is a module path of your new app.
- Initialize a project.

```console
gonew github.com/syumai/workers/_templates/cloudflare/worker-go your.module/my-app # e.g. github.com/syumai/my-app
cd my-app
go mod init
go mod tidy
make dev # start running dev server
npm start # start running dev server
curl http://localhost:8787/hello # outputs "Hello!"
```

- To change worker name, please edit `name` property in `wrangler.toml`.

## Development

### Commands

```
make dev # run dev server
make build # build Go Wasm binary
make deploy # deploy worker
npm start # run dev server
# or
go run . # run dev server without Wrangler (Cloudflare-related features are not available)
npm run build # build Go Wasm binary
npm run deploy # deploy worker
```

### Testing dev server
Expand Down
14 changes: 14 additions & 0 deletions _templates/cloudflare/worker-go/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "<TBD>",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "go run github.com/syumai/workers/cmd/workers-assets-gen -mode=go && GOOS=js GOARCH=wasm go build -o ./build/app.wasm .",
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"start": "wrangler dev"
},
"devDependencies": {
"wrangler": "^3.109.2"
}
}
8 changes: 8 additions & 0 deletions _templates/cloudflare/worker-go/wrangler.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "<TBD>",
"main": "./build/worker.mjs",
"compatibility_date": "<TBD>",
"build": {
"command": "npm run build"
}
}
6 changes: 0 additions & 6 deletions _templates/cloudflare/worker-go/wrangler.toml

This file was deleted.

12 changes: 0 additions & 12 deletions _templates/cloudflare/worker-tinygo/Makefile

This file was deleted.

27 changes: 12 additions & 15 deletions _templates/cloudflare/worker-tinygo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,36 @@
## Requirements

- Node.js
- [wrangler](https://developers.cloudflare.com/workers/wrangler/)
- just run `npm install -g wrangler`
- tinygo 0.29.0 or later
- tinygo 0.35.0 or later

## Getting Started

* If not already installed, please install the [gonew](https://pkg.go.dev/golang.org/x/tools/cmd/gonew) command.
- Create a new worker project using this template.

```console
go install golang.org/x/tools/cmd/gonew@latest
npm create cloudflare@latest -- --template github.com/syumai/workers/_templates/cloudflare/worker-tinygo
```

* Create a new project using this template.
- Second argument passed to `gonew` is a module path of your new app.
- Initialize a project.

```console
gonew github.com/syumai/workers/_templates/cloudflare/worker-tinygo your.module/my-app # e.g. github.com/syumai/my-app
cd my-app
cd my-app # A directory of the project created by the above command
go mod init
go mod tidy
make dev # start running dev server
npm start # start running dev server
curl http://localhost:8787/hello # outputs "Hello!"
```

- To change worker name, please edit `name` property in `wrangler.toml`.

## Development

### Commands

```
make dev # run dev server
make build # build Go Wasm binary
make deploy # deploy worker
npm start # run dev server
# or
go run . # run dev server without Wrangler (Cloudflare-related features are not available)
npm run build # build Go Wasm binary
npm run deploy # deploy worker
```

### Testing dev server
Expand Down
3 changes: 0 additions & 3 deletions _templates/cloudflare/worker-tinygo/go.mod

This file was deleted.

14 changes: 14 additions & 0 deletions _templates/cloudflare/worker-tinygo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "<TBD>",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "go run github.com/syumai/workers/cmd/workers-assets-gen && tinygo build -o ./build/app.wasm -target wasm -no-debug ./...",
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"start": "wrangler dev"
},
"devDependencies": {
"wrangler": "^3.109.2"
}
}
8 changes: 8 additions & 0 deletions _templates/cloudflare/worker-tinygo/wrangler.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "<TBD>",
"main": "./build/worker.mjs",
"compatibility_date": "<TBD>",
"build": {
"command": "npm run build"
}
}
6 changes: 0 additions & 6 deletions _templates/cloudflare/worker-tinygo/wrangler.toml

This file was deleted.

Loading