• Stars
    star
    614
  • Rank 73,061 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go package to run an HTTP server on Cloudflare Workers.

workers

Go Reference Discord Server

  • workers is a package to run an HTTP server written in Go on Cloudflare Workers.
  • This package can easily serve http.Handler on Cloudflare Workers.
  • Caution: This is an experimental project.

Features

  • serve http.Handler
  • R2
    • Head
    • Get
    • Put
    • Delete
    • List
    • Options for R2 methods
  • KV
    • Get
    • List
    • Put
    • Delete
    • Options for KV methods
  • Cache API
  • Durable Objects
    • Calling stubs
  • D1 (alpha)
  • Environment variables
  • FetchEvent
  • Cron Triggers

Installation

go get github.com/syumai/workers

Usage

implement your http.Handler and give it to workers.Serve().

func main() {
	var handler http.HandlerFunc = func (w http.ResponseWriter, req *http.Request) { ... }
	workers.Serve(handler)
}

or just call http.Handle and http.HandleFunc, then invoke workers.Serve() with nil.

func main() {
	http.HandleFunc("/hello", func (w http.ResponseWriter, req *http.Request) { ... })
	workers.Serve(nil) // if nil is given, http.DefaultServeMux is used.
}

For concrete examples, see _examples directory. Currently, all examples use tinygo instead of Go due to binary size issues.

Quick Start

First, please install the following tools:

  • Node.js (and npm)
  • wrangler
    • You can install it by running npm install -g wrangler.
  • tinygo

After installation, please run the following commands.

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!"

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

FAQ

How do I deploy a worker implemented in this package?

To deploy a Worker, the following steps are required.

  • Create a worker project using wrangler.
  • Build a Wasm binary.
  • Upload a Wasm binary with a JavaScript code to load and instantiate Wasm (for entry point).

The worker-tinygo template contains all the required files, so I recommend using this template.

The worker-go template (using regular Go, not tinygo) is also available, but it requires a paid plan of Cloudflare Workers (due to the large binary size).

Where can I have discussions about contributions, or ask questions about how to use the library?

You can do both through GitHub Issues. If you want to have a more casual conversation, please use the Discord server.

More Repositories

1

dinatra

Sinatra like light weight web app framework for deno.
TypeScript
413
star
2

dejs

ejs template engine for deno.
TypeScript
143
star
3

dem

A module version manager for Deno.
TypeScript
61
star
4

trollo

Simple Trello clone implemented with Vue.js and Vuex
Vue
47
star
5

worker-template-tinygo

A template for starting a Cloudflare Worker project with tinygo.
Go
32
star
6

deno-libs

Simple commands implemented for deno.
TypeScript
30
star
7

go-image-proxy-worker

A Cloudflare Worker application which serves patched version of imageproxy.
JavaScript
26
star
8

sed-awk-hands-on-ja

Go
25
star
9

workers-playground

my playground for Cloudflare Workers.
JavaScript
22
star
10

denoio

denoio is a Go package to bind Deno and Go(Wasm)'s I/O interfaces.
TypeScript
21
star
11

go-jpostcode

a Go package to find Japanese address data from Japanese postal code
Go
20
star
12

syumaigen

A CLI tool to generate syumai's avatar image
Go
20
star
13

gpgsync

The Go Playground with coedit mode.
JavaScript
19
star
14

go-hyperscript

hyperscript implementation in Go.
Go
18
star
15

emotter

A web app to post emoji implemented in connect-go and connect-web.
TypeScript
16
star
16

denoboard

message board application implemented in Deno
TypeScript
16
star
17

sunmi-namecard-printer

Name card printer app for Sunmi devices.
TypeScript
15
star
18

go-wasm-todo-list

ToDo List App implemented in Go + WebAssembly.
JavaScript
14
star
19

sandboxed-eval

iframe-sandboxed eval working on the browser.
JavaScript
14
star
20

goplayground-vim

A Vim plugin to add commands to call The Go Playground from Vim.
TypeScript
13
star
21

hono-middleware-go

A package to write Hono middleware in Go or TinyGo.
JavaScript
13
star
22

go-wasm-sizes

compare WebAssembly build size depends on imported package.
Makefile
12
star
23

vue-native-custom-transformer-plugin

Custom transformer plugin for vue-native
JavaScript
12
star
24

deno-deploy-scale-image

image scaling app built on Deno Deploy and Go WebAssembly.
TypeScript
12
star
25

longify

A command to output longified ascii art.
Go
11
star
26

wee-chat

Sample Chat app implemented in Weex and WebSocket
JavaScript
10
star
27

denoget

A tool to install executable deno script.
TypeScript
10
star
28

go-playground-addons

Chrome Extension for the Go Playground
TypeScript
9
star
29

react-sidebar-layout

TypeScript
8
star
30

ffmpeg-device-list-parser

Parser of FFmpeg device list - written in Node.js
JavaScript
8
star
31

goplayground-js

The Go Playground API client for JavaScript written in TypeScript.
TypeScript
7
star
32

emo

a CLI tool to find emojis with fuzzy-find window.
Go
7
star
33

printpdf

A utility to print page to PDF using chromedp.
Go
7
star
34

cli

Small CLI tools
JavaScript
6
star
35

genericsutil

utilities for Go 1.18 generics.
Go
6
star
36

protocat

A CLI tool to concatenate multiple proto files into a single file.
Go
6
star
37

deno-wasm-playground

TypeScript
5
star
38

syum.ai

A web app hosted on syum.ai
Go
5
star
39

tinyutil

utilities for tinygo + Wasm.
JavaScript
5
star
40

worker-template-go

A template for starting a Cloudflare Worker project with Go.
Go
5
star
41

go-wasm-gzipper

JavaScript
5
star
42

marp-pages-example

A Cloudflare Pages application which renders Marp slides without static site generation.
TypeScript
5
star
43

gospec-previewer

A simple web application to preview specified version of Go Language Specification.
TypeScript
5
star
44

til

Today I learned
WebAssembly
4
star
45

hono-esbuild-bundler-middleware

esbuild Bundler Middleware for Hono
TypeScript
4
star
46

uuidgenseeded

A CLI tool to generate UUID with seed text.
Go
4
star
47

go-wasm-playground

JavaScript
4
star
48

tcpstudy

Go
4
star
49

social.syum.ai

Wildebeest server served on social.syum.ai
TypeScript
3
star
50

proconutil

Go utils for programming contests
Go
3
star
51

go-dayjs

day.js wrapper package for Go based on goja.
Go
3
star
52

vue-native-example-app

Example app of Vue Native with https://github.com/syumai/vue-native-custom-transformer-plugin
Vue
3
star
53

hyper-reversi

Reversi game implemented in Hyperapp
JavaScript
3
star
54

gorunner

gorunner runs Go script in safe WebAssembly environment using Node.js
Go
3
star
55

react-vue-native-chat

[WIP] This is sample implementation of chat app with react-vue-native-scripts
JavaScript
2
star
56

syumai

Profile page of syumai
2
star
57

tt

A test runner for deno based on go test.
TypeScript
2
star
58

go-playground-custom

A customized version of The Go Playground with rich features.
JavaScript
2
star
59

deno-docker

Docker image to run deno in safe place.
Dockerfile
2
star
60

webpacker-docker-example

Example application of RoR with webpacker 3 and docker-compose
Ruby
2
star
61

binpack

TypeScript
2
star
62

runa

A utility to convert characters and code points
Go
2
star
63

go117-generics-investigation

A set of code to investigate generic code works with Go 1.17.
Go
1
star
64

go-wasm-counter

Example counter app written in go. This app runs on browser with wasm build.
JavaScript
1
star
65

followfilter

Find twitter followers or followees who has a name with specified keyword.
Go
1
star
66

goja-cli

A CLI tool to run goja in terminal.
Go
1
star
67

zenn

Articles for Zenn
1
star
68

heroku-config-bot

Herokuサーバの環境変数を設定してくれるSlack bot
JavaScript
1
star
69

file-zipper

Utility for downloading multiple files as zip
JavaScript
1
star
70

study-compilerbook

C
1
star
71

gear360pano

Docker image of gear360pano https://github.com/ultramango/gear360pano
1
star
72

sunmi-receiptline-printer

WIP - An app for Sunmi devices to print recepit written in receiptline.
TypeScript
1
star
73

ditherer

A CLI tool to convert PNG into dithered image.
JavaScript
1
star
74

vue-synched-columns

Synchronized multiple columns implemented in Vue.js.
JavaScript
1
star
75

asset-prefix-example

JavaScript
1
star
76

postmail

CLI tool to send email using LOGIN auth
Go
1
star
77

embed-example

An example of web application using Go 1.16's embed.
TypeScript
1
star
78

vue-fade-carousel

Carousel with fade animation implemented in Vue.js
Vue
1
star
79

go-generics

an experimental implementation of Go's Generics packages based on the Proposal document.
Go
1
star
80

go-jsutil

A set of utilities for Go programs which communicate with JavaScript via syscall/js.
Go
1
star
81

sd-cloudflare-examples

TypeScript
1
star
82

syumai.deno.dev

TypeScript
1
star