-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add pipe example in go and nodejs
- Loading branch information
Showing
11 changed files
with
139 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea/ | ||
**/node_modules/ | ||
**/dist/ | ||
**/dist/ | ||
./flatend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# pipe | ||
|
||
Whatever comes in must come out. Simple piping example: upload a file to POST /pipe. | ||
|
||
``` | ||
$ flatend | ||
2020/06/17 01:07:12 Listening for microservices on '127.0.0.1:9000'. | ||
2020/06/17 01:07:12 Listening for HTTP requests on '[::]:3000'. | ||
2020/06/17 01:07:17 ??? has connected to you. Services: [pipe] | ||
$ go run main.go | ||
2020/06/17 01:07:17 You are now connected to 127.0.0.1:9000. Services: [] | ||
$ POST /pipe (1.6MiB GIF) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
addr = "127.0.0.1:9000" | ||
|
||
[[http]] | ||
addr = ":3000" | ||
|
||
[[http.routes]] | ||
path = "POST /pipe" | ||
service = "pipe" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/lithdew/flatend" | ||
"io" | ||
"os" | ||
"os/signal" | ||
) | ||
|
||
func check(err error) { | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func pipe(ctx *flatend.Context) { | ||
_, _ = io.Copy(ctx, ctx.Body) | ||
} | ||
|
||
func main() { | ||
node := &flatend.Node{ | ||
Services: map[string]flatend.Handler{ | ||
"pipe": pipe, | ||
}, | ||
} | ||
check(node.Start("127.0.0.1:9000")) | ||
|
||
ch := make(chan os.Signal, 1) | ||
signal.Notify(ch, os.Interrupt) | ||
<-ch | ||
|
||
node.Shutdown() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# pipe | ||
|
||
Whatever comes in must come out. Simple piping example: upload a file to POST /pipe. | ||
|
||
``` | ||
$ flatend | ||
2020/06/17 01:07:12 Listening for microservices on '127.0.0.1:9000'. | ||
2020/06/17 01:07:12 Listening for HTTP requests on '[::]:3000'. | ||
2020/06/17 01:07:17 ??? has connected to you. Services: [pipe] | ||
$ node index.js | ||
Successfully dialed 127.0.0.1:9000. Services: [] | ||
$ POST /pipe (1.6MiB GIF) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const {Node} = require("flatend"); | ||
|
||
const main = async () => { | ||
const node = new Node(); | ||
node.register('pipe', ctx => ctx.pipe(ctx)); | ||
await node.dial("127.0.0.1:9000"); | ||
} | ||
|
||
main().catch(err => console.error(err)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "pipe", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"flatend": "^0.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
blake2b-wasm@^1.1.0: | ||
version "1.1.7" | ||
resolved "https://registry.yarnpkg.com/blake2b-wasm/-/blake2b-wasm-1.1.7.tgz#e4d075da10068e5d4c3ec1fb9accc4d186c55d81" | ||
integrity sha512-oFIHvXhlz/DUgF0kq5B1CqxIDjIJwh9iDeUUGQUcvgiGz7Wdw03McEO7CfLBy7QKGdsydcMCgO9jFNBAFCtFcA== | ||
dependencies: | ||
nanoassert "^1.0.0" | ||
|
||
blake2b@^2.1.3: | ||
version "2.1.3" | ||
resolved "https://registry.yarnpkg.com/blake2b/-/blake2b-2.1.3.tgz#f5388be424768e7c6327025dad0c3c6d83351bca" | ||
integrity sha512-pkDss4xFVbMb4270aCyGD3qLv92314Et+FsKzilCLxDz5DuZ2/1g3w4nmBbu6nKApPspnjG7JcwTjGZnduB1yg== | ||
dependencies: | ||
blake2b-wasm "^1.1.0" | ||
nanoassert "^1.0.0" | ||
|
||
flatend@^0.0.1: | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/flatend/-/flatend-0.0.1.tgz#b4d4155dccf7ad696f585929accb8c9196e57b0f" | ||
integrity sha512-QtIEOOCvWhl22KUdpRVgkvJK4ztYutXaGw9Dgyy4++h0esNoQ+pFek8JwyGbyiUXMO++0Lt/mR9IOsPLsHmn5Q== | ||
dependencies: | ||
blake2b "^2.1.3" | ||
ip "^1.1.5" | ||
tweetnacl "^1.0.3" | ||
|
||
ip@^1.1.5: | ||
version "1.1.5" | ||
resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.5.tgz#bdded70114290828c0a039e72ef25f5aaec4354a" | ||
integrity sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo= | ||
|
||
nanoassert@^1.0.0: | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/nanoassert/-/nanoassert-1.1.0.tgz#4f3152e09540fde28c76f44b19bbcd1d5a42478d" | ||
integrity sha1-TzFS4JVA/eKMdvRLGbvNHVpCR40= | ||
|
||
tweetnacl@^1.0.3: | ||
version "1.0.3" | ||
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596" | ||
integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw== |