Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add wasm-go and sfn.wait() #638

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ out
next-env.d.ts
.next
.vercel
public
1 change: 1 addition & 0 deletions docs/pages/docs/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"wasm-rust": "Write StreamFunction in Rust",
"wasm-zig": "Write StreamFunction in Zig",
"wasm-c": "Write StreamFunction in C",
"wasm-go": "Write StreamFunction in Go",
"---Observability": {
"type": "separator",
"title": "Observability"
Expand Down
4 changes: 4 additions & 0 deletions docs/pages/docs/api/sfn.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ Write data to [Zipper][zipper].

Close the connection to [Zipper][zipper].

### sfn.Wait()

Wait until the function fulfilled.

## type SfnOption

### func WithObserveDataTags(tags ...Tag) SfnOption
Expand Down
83 changes: 83 additions & 0 deletions docs/pages/docs/wasm-go.mdx
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>