-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from extism/feat/reactor-module
feat: create separate package to make reactor modules easier
- Loading branch information
Showing
9 changed files
with
102 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
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,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: | ||
|
||
```bash | ||
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: | ||
```bash | ||
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 | ||
``` |
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 @@ | ||
Hello World! |
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,26 @@ | ||
//go:build !std | ||
// +build !std | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/extism/go-pdk" | ||
_ "github.com/extism/go-pdk/wasi-reactor" | ||
) | ||
|
||
//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() {} |
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,6 @@ | ||
go 1.21.1 | ||
|
||
use ( | ||
. | ||
./wasi-reactor | ||
) |
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,9 @@ | ||
package reactor | ||
|
||
//export __wasm_call_ctors | ||
func __wasm_call_ctors() | ||
|
||
//export _initialize | ||
func _initialize() { | ||
__wasm_call_ctors() | ||
} |
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,3 @@ | ||
module github.com/extism/go-pdk/wasi-reactor | ||
|
||
go 1.21.1 |