Skip to content

Commit 958c11a

Browse files
authored
Merge pull request #5 from madflojo/godocs
2 parents 5aacd3a + 4a6996d commit 958c11a

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

callbacks/router.go

+31
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,37 @@ When a host initiates the waPC engine, it can register a single function to hand
1212
The callbacks package provides a router that can be registered with the waPC engine. It enables
1313
routing host calls based on the Namespace, Capability, and Operation specified by the guest module.
1414
Hosts can extend many different capabilities to guest modules with the callback router.
15+
16+
Usage:
17+
18+
// Create a new router
19+
router, err := New(RouterConfig{})
20+
if err != nil {
21+
// do something
22+
}
23+
defer router.Close()
24+
25+
// Register the callback with the router
26+
err = router.RegisterCallback(CallbackConfig{
27+
Namespace: "example",
28+
Capability: "greeting",
29+
Operation: "hello",
30+
Func: func(_ []byte) ([]byte, error) {
31+
fmt.Println("Hello World!")
32+
return []byte(""), nil
33+
},
34+
})
35+
if err != nil {
36+
// do something
37+
}
38+
39+
// Register router with waPC engine
40+
engine, err = engine.New(engine.ServerConfig{
41+
Callback: router.Callback,
42+
})
43+
if err != nil {
44+
// do something
45+
}
1546
*/
1647
package callbacks
1748

engine/wasm.go

+35
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,41 @@ Use this package if you have a Go application and want to enable extended functi
1515
1616
Examples of use cases could be stored procedures within a database, serverless functions, or
1717
language-agnostic plugins.
18+
19+
Usage:
20+
21+
import (
22+
"github.com/tarmac-project/wapc-toolkit/engine"
23+
)
24+
25+
func main() {
26+
// Create a new engine server.
27+
server, err := engine.New(ServerConfig{})
28+
if err != nil {
29+
// do something
30+
}
31+
32+
// Load the guest module.
33+
err = server.LoadModule(engine.ModuleConfig{
34+
Name: "my-guest-module",
35+
Filepath: "./my-guest-module.wasm",
36+
})
37+
if err != nil {
38+
// do something
39+
}
40+
41+
// Lookup the guest module.
42+
m, err := server.Module("my-guest-module")
43+
if err != nil {
44+
// do something
45+
}
46+
47+
// Call the Hello function within the guest module.
48+
rsp, err := m.Run("Hello", []byte("world"))
49+
if err != nil {
50+
// do something
51+
}
52+
}
1853
*/
1954
package engine
2055

0 commit comments

Comments
 (0)