-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add wasm-go and sfn.wait() (#638)
- add: https://yomo-git-docs-sfn-wait-yomorun.vercel.app/docs/wasm-go - add: https://yomo-git-docs-sfn-wait-yomorun.vercel.app/docs/api/sfn#sfnwait
- Loading branch information
1 parent
8cb3db6
commit 1c34dab
Showing
4 changed files
with
89 additions
and
0 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 |
---|---|---|
|
@@ -10,3 +10,4 @@ out | |
next-env.d.ts | ||
.next | ||
.vercel | ||
public |
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,83 @@ | ||
--- | ||
title: Implement StreamFunction in Go | ||
--- | ||
|
||
import { Steps, Callout } from 'nextra-theme-docs' | ||
|
||
# Implement StreamFunction in [Golang](https://go.dev/) | ||
|
||
<Callout emoji="🚧" type="warning"> | ||
This feature is currently in alpha and subject to change. | ||
</Callout> | ||
|
||
<Steps> | ||
### Install CLI | ||
|
||
```bash | ||
$ curl -fsSL "https://get.yomo.run" | sh | ||
``` | ||
|
||
[Install TinyGo](https://tinygo.org/getting-started/install/) | ||
|
||
on Mac: | ||
|
||
```bash | ||
$ brew tap tinygo-org/tools | ||
$ brew install tinygo | ||
``` | ||
|
||
### Write a StreamFunction in Go | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/yomorun/yomo/serverless" | ||
"github.com/yomorun/yomo/serverless/guest" | ||
) | ||
|
||
func main() { | ||
guest.DataTags = DataTags | ||
guest.Handler = Handler | ||
guest.Init = Init | ||
} | ||
|
||
// Init will initialize the stream function | ||
func Init() error { | ||
fmt.Println("wasm go sfn init") | ||
return nil | ||
} | ||
|
||
func Handler(ctx serverless.Context) { | ||
// load input data | ||
tag := ctx.Tag() | ||
input := ctx.Data() | ||
fmt.Printf("wasm go sfn received %d bytes with tag[%#x]\n", len(input), tag) | ||
|
||
// process app data | ||
output := strings.ToUpper(string(input)) | ||
|
||
// write result to zipper | ||
ctx.Write(0x34, []byte(output)) | ||
} | ||
|
||
func DataTags() []uint32 { | ||
return []uint32{0x33} | ||
} | ||
``` | ||
|
||
### Compile to [WASI](https://wasi.dev/) | ||
|
||
```bash | ||
$ tinygo build -o sfn.wasm -no-debug -target wasi | ||
``` | ||
|
||
### Run Streaming Serverless Function | ||
|
||
```bash | ||
yomo run /path/to/sfn.wasm | ||
``` | ||
</Steps> |