F: add stream large file example

This commit is contained in:
aki-0421 2024-01-25 08:56:56 +09:00
parent afebbac9d5
commit 8881a04947
No known key found for this signature in database
GPG Key ID: 64A8CF6D437D166A
7 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,3 @@
build
node_modules
.wrangler

View File

@ -0,0 +1,12 @@
.PHONY: dev
dev:
wrangler dev
.PHONY: build
build:
go run ../../cmd/workers-assets-gen
tinygo build -o ./build/app.wasm -target wasm -no-debug ./...
.PHONY: deploy
deploy:
wrangler deploy

View File

@ -0,0 +1,18 @@
# stream-large-file
## Development
### Requirements
This project requires these tools to be installed globally.
* wrangler
* tinygo
### Commands
```
make dev # run dev server
make build # build Go Wasm binary
make deploy # deploy worker
```

View File

@ -0,0 +1,7 @@
module github.com/syumai/workers/_examples/stream
go 1.21.3
require github.com/syumai/workers v0.0.0
replace github.com/syumai/workers => ../../

View File

@ -0,0 +1,2 @@
github.com/syumai/workers v0.1.0 h1:z5QfQR2X+PCKzom7RodpI5J4D5YF7NT7Qwzb9AM9dgY=
github.com/syumai/workers v0.1.0/go.mod h1:alXIDhTyeTwSzh0ZgQ3cb9HQPyyYfIejupE4Z3efr14=

View File

@ -0,0 +1,26 @@
package main
import (
"fmt"
"io"
"net/http"
"github.com/syumai/workers"
"github.com/syumai/workers/cloudflare/fetch"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
cli := fetch.NewClient().HTTPClient(fetch.RedirectModeFollow)
resp, err := cli.Get("http://tyo.download.datapacket.com/1000mb.bin")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "err: %v", err)
return
}
defer resp.Body.Close()
io.Copy(w, resp.Body)
})
workers.Serve(nil)
}

View File

@ -0,0 +1,6 @@
name = "stream-large-file"
main = "./build/worker.mjs"
compatibility_date = "2023-12-01"
[build]
command = "make build"