Skip to content

Commit

Permalink
Merge pull request #5 from madflojo/godocs
Browse files Browse the repository at this point in the history
  • Loading branch information
madflojo authored Jul 26, 2024
2 parents 5aacd3a + 4a6996d commit 958c11a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
31 changes: 31 additions & 0 deletions callbacks/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,37 @@ When a host initiates the waPC engine, it can register a single function to hand
The callbacks package provides a router that can be registered with the waPC engine. It enables
routing host calls based on the Namespace, Capability, and Operation specified by the guest module.
Hosts can extend many different capabilities to guest modules with the callback router.
Usage:
// Create a new router
router, err := New(RouterConfig{})
if err != nil {
// do something
}
defer router.Close()
// Register the callback with the router
err = router.RegisterCallback(CallbackConfig{
Namespace: "example",
Capability: "greeting",
Operation: "hello",
Func: func(_ []byte) ([]byte, error) {
fmt.Println("Hello World!")
return []byte(""), nil
},
})
if err != nil {
// do something
}
// Register router with waPC engine
engine, err = engine.New(engine.ServerConfig{
Callback: router.Callback,
})
if err != nil {
// do something
}
*/
package callbacks

Expand Down
35 changes: 35 additions & 0 deletions engine/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,41 @@ Use this package if you have a Go application and want to enable extended functi
Examples of use cases could be stored procedures within a database, serverless functions, or
language-agnostic plugins.
Usage:
import (
"github.com/tarmac-project/wapc-toolkit/engine"
)
func main() {
// Create a new engine server.
server, err := engine.New(ServerConfig{})
if err != nil {
// do something
}
// Load the guest module.
err = server.LoadModule(engine.ModuleConfig{
Name: "my-guest-module",
Filepath: "./my-guest-module.wasm",
})
if err != nil {
// do something
}
// Lookup the guest module.
m, err := server.Module("my-guest-module")
if err != nil {
// do something
}
// Call the Hello function within the guest module.
rsp, err := m.Run("Hello", []byte("world"))
if err != nil {
// do something
}
}
*/
package engine

Expand Down

0 comments on commit 958c11a

Please sign in to comment.