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

feat: create separate package to make reactor modules easier #26

Merged
merged 4 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions example/reactor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Reactor module example
By including this package, you'll turn your plugin into a [Reactor](https://dylibso.com/blog/wasi-command-reactor/) module. This makes sure that you can use WASI (e.g. File Access) in your exported functions.

To test this example, run:

```
tinygo build -target wasi -o reactor.wasm .\tiny_main.go
extism call ./reactor.wasm read_file --input "./test.txt" --allow-path . --wasi --log-level info
// => Hello World!
```

If you don't include the pacakge, you'll see this output:
```
extism call .\c.wasm read_file --input "./test.txt" --allow-path . --wasi --log-level info
// => 2024/01/18 20:48:48 open ./test.txt: errno 76
```
1 change: 1 addition & 0 deletions example/reactor/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
26 changes: 26 additions & 0 deletions example/reactor/tiny_main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//go:build !std
// +build !std

package main

import (
"os"

"github.com/extism/go-pdk"
_ "github.com/extism/go-pdk/pdk_reactor"
mhmd-azeez marked this conversation as resolved.
Show resolved Hide resolved
)

//export read_file
func read_file() {
name := pdk.InputString()

content, err := os.ReadFile(name)
if err != nil {
pdk.Log(pdk.LogError, err.Error())
return
}

pdk.Output(content)
}

func main() {}
6 changes: 6 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.21.1

use (
.
./pdk_reactor
)
9 changes: 9 additions & 0 deletions pdk_reactor/extism_pdk_reactor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pdk_reactor
mhmd-azeez marked this conversation as resolved.
Show resolved Hide resolved

//export __wasm_call_ctors
func __wasm_call_ctors()

//export _initialize
func _initialize() {
__wasm_call_ctors()
}
3 changes: 3 additions & 0 deletions pdk_reactor/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/extism/go-pdk/pdk_reactor
mhmd-azeez marked this conversation as resolved.
Show resolved Hide resolved

go 1.21.1
Loading