Skip to content

Commit

Permalink
docs: add wasm-go and sfn.wait() (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
fanweixiao authored Oct 7, 2023
1 parent 8cb3db6 commit 1c34dab
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
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>

0 comments on commit 1c34dab

Please sign in to comment.