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

Improving godocs with usage examples #5

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading