Skip to content

Commit e7340db

Browse files
committed
mention the package in the readme
1 parent 1369b9c commit e7340db

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,44 @@ python3 app.py
326326
# => An argument to send to Python!
327327
```
328328

329+
## Reactor modules
330+
331+
Since TinyGo doesn't support [Reactor modules](https://dylibso.com/blog/wasi-command-reactor/) yet, If you want to use WASI inside your Reactor module functions (exported functions other than `main`), you'll need to import `wasi-reactor` module which makes sure libc and go runtime are properly initialized:
332+
333+
```go
334+
package main
335+
336+
import (
337+
"os"
338+
339+
"github.com/extism/go-pdk"
340+
_ "github.com/extism/go-pdk/wasi-reactor"
341+
)
342+
343+
//export read_file
344+
func read_file() {
345+
name := pdk.InputString()
346+
347+
content, err := os.ReadFile(name)
348+
if err != nil {
349+
pdk.Log(pdk.LogError, err.Error())
350+
return
351+
}
352+
353+
pdk.Output(content)
354+
}
355+
356+
func main() {}
357+
```
358+
359+
```bash
360+
tinygo build -target wasi -o reactor.wasm .\tiny_main.go
361+
extism call ./reactor.wasm read_file --input "./test.txt" --allow-path . --wasi --log-level info
362+
# => Hello World!
363+
```
364+
365+
Note: this is not required if you only have the `main` function.
366+
329367
### Reach Out!
330368

331369
Have a question or just want to drop in and say hi? [Hop on the Discord](https://extism.org/discord)!

example/reactor/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ By including this package, you'll turn your plugin into a [Reactor](https://dyli
33

44
To test this example, run:
55

6-
```
6+
```bash
77
tinygo build -target wasi -o reactor.wasm .\tiny_main.go
88
extism call ./reactor.wasm read_file --input "./test.txt" --allow-path . --wasi --log-level info
9-
// => Hello World!
9+
# => Hello World!
1010
```
1111

1212
If you don't include the pacakge, you'll see this output:
13-
```
13+
```bash
1414
extism call .\c.wasm read_file --input "./test.txt" --allow-path . --wasi --log-level info
15-
// => 2024/01/18 20:48:48 open ./test.txt: errno 76
15+
# => 2024/01/18 20:48:48 open ./test.txt: errno 76
1616
```

0 commit comments

Comments
 (0)