mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 09:27:08 +00:00
F: add stream large file example
This commit is contained in:
parent
afebbac9d5
commit
8881a04947
3
_examples/stream-large-file/.gitignore
vendored
Normal file
3
_examples/stream-large-file/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
build
|
||||
node_modules
|
||||
.wrangler
|
12
_examples/stream-large-file/Makefile
Normal file
12
_examples/stream-large-file/Makefile
Normal 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
|
18
_examples/stream-large-file/README.md
Normal file
18
_examples/stream-large-file/README.md
Normal 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
|
||||
```
|
7
_examples/stream-large-file/go.mod
Normal file
7
_examples/stream-large-file/go.mod
Normal 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 => ../../
|
2
_examples/stream-large-file/go.sum
Normal file
2
_examples/stream-large-file/go.sum
Normal 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=
|
26
_examples/stream-large-file/main.go
Normal file
26
_examples/stream-large-file/main.go
Normal 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)
|
||||
}
|
6
_examples/stream-large-file/wrangler.toml
Normal file
6
_examples/stream-large-file/wrangler.toml
Normal file
@ -0,0 +1,6 @@
|
||||
name = "stream-large-file"
|
||||
main = "./build/worker.mjs"
|
||||
compatibility_date = "2023-12-01"
|
||||
|
||||
[build]
|
||||
command = "make build"
|
Loading…
x
Reference in New Issue
Block a user