{"id":13489673,"url":"https://github.com/wapc/wapc-go","last_synced_at":"2025-10-07T04:08:43.100Z","repository":{"id":39644821,"uuid":"264294914","full_name":"wapc/wapc-go","owner":"wapc","description":"Golang-based WebAssembly Host Runtime for waPC-compliant modules","archived":false,"fork":false,"pushed_at":"2025-02-20T02:09:43.000Z","size":1261,"stargazers_count":100,"open_issues_count":4,"forks_count":25,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-20T03:22:46.548Z","etag":null,"topics":["rpc","rpc-framework","wapc","wasm","webassembly"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wapc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-15T20:44:06.000Z","updated_at":"2025-02-20T02:08:35.000Z","dependencies_parsed_at":"2023-01-31T20:32:10.551Z","dependency_job_id":"fe8eefd2-9d4d-457a-97f6-0c4c16cf5b94","html_url":"https://github.com/wapc/wapc-go","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wapc%2Fwapc-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wapc%2Fwapc-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wapc%2Fwapc-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wapc%2Fwapc-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wapc","download_url":"https://codeload.github.com/wapc/wapc-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245978200,"owners_count":20703675,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rpc","rpc-framework","wapc","wasm","webassembly"],"created_at":"2024-07-31T19:00:32.942Z","updated_at":"2025-10-07T04:08:38.069Z","avatar_url":"https://github.com/wapc.png","language":"Go","funding_links":[],"categories":["waPC - WebAssembly Procedure Calls","\u003ca name=\"wazero\"\u003e\u003c/a\u003e[wazero](https://wazero.io) \u003csup\u003e[top⇈](#contents)\u003c/sup\u003e"],"sub_categories":[],"readme":"# waPC Host for Go\n\n[![Gitter](https://badges.gitter.im/wapc/community.svg)](https://gitter.im/wapc/community)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/wapc/wapc-go)](https://pkg.go.dev/github.com/wapc/wapc-go)\n[![Go Report Card](https://goreportcard.com/badge/github.com/wapc/wapc-go)](https://goreportcard.com/report/github.com/wapc/wapc-go)\n[![go tests](https://github.com/wapc/wapc-go/actions/workflows/go-test.yml/badge.svg)](https://github.com/wapc/wapc-go/actions/workflows/go-test.yml)\n\nThis is the Golang implementation of the **waPC** standard for WebAssembly host runtimes. It allows any WebAssembly module to be loaded as a guest and receive requests for invocation as well as to make its own function requests of the host.\n\n## Example\n\nThe following is a simple example of synchronous, bidirectional procedure calls between a WebAssembly host runtime and the guest module.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n\n\t\"github.com/wapc/wapc-go\"\n\t\"github.com/wapc/wapc-go/engines/wazero\"\n)\n\nfunc main() {\n\tif len(os.Args) \u003c 2 {\n\t\tfmt.Println(\"usage: hello \u003cname\u003e\")\n\t\treturn\n\t}\n\tname := os.Args[1]\n\tctx := context.Background()\n\tguest, err := os.ReadFile(\"hello/hello.wasm\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tengine := wazero.Engine()\n\n\tmodule, err := engine.New(ctx, host, guest, \u0026wapc.ModuleConfig{\n\t\tLogger: wapc.PrintlnLogger,\n\t\tStdout: os.Stdout,\n\t\tStderr: os.Stderr,\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer module.Close(ctx)\n\n\tinstance, err := module.Instantiate(ctx)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer instance.Close(ctx)\n\n\tresult, err := instance.Invoke(ctx, \"hello\", []byte(name))\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(string(result))\n}\n\nfunc host(ctx context.Context, binding, namespace, operation string, payload []byte) ([]byte, error) {\n\t// Route the payload to any custom functionality accordingly.\n\t// You can even route to other waPC modules!!!\n\tswitch namespace {\n\tcase \"example\":\n\t\tswitch operation {\n\t\tcase \"capitalize\":\n\t\t\tname := string(payload)\n\t\t\tname = strings.Title(name)\n\t\t\treturn []byte(name), nil\n\t\t}\n\t}\n\treturn []byte(\"default\"), nil\n}\n```\n\nTo see this in action, enter the following in your shell:\n\n```\n$ go run example/main.go waPC!\nhello called\nHello, WaPC!\n```\n\nAlternatively you can use a `Pool` to manage a pool of instances.\n\n```go\n\tpool, err := wapc.NewPool(ctx, module, 10, func(instance wapc.Instance) error {\n\t\t// Do something to initialize this instance before use.\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer pool.Close(ctx)\n\n\tfor i := 0; i \u003c 100; i++ {\n\t\tinstance, err := pool.Get(10 * time.Millisecond)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\tresult, err := instance.Invoke(ctx, \"hello\", []byte(\"waPC\"))\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\tfmt.Println(string(result))\n\n\t\terr = pool.Return(instance)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t}\n```\n\nWhile the above example uses wazero, wapc-go is decoupled (via [`wapc.Engine`](#engines)) and can be used with different runtimes.\n\n## Engines\n\nHere are the supported `wapc.Engine` implementations, in alphabetical order:\n\n|    Name     |        Usage        | Build Tag |                                                Package                                                |\n|:-----------:|:-------------------:|-----------|:-----------------------------------------------------------------------------------------------------:|\n|  wasmer-go  |  `wasmer.Engine()`  | wasmer    |           [github.com/wasmerio/wasmer-go](https://pkg.go.dev/github.com/wasmerio/wasmer-go)           |\n| wasmtime-go | `wasmtime.Engine()` | wasmtime  | [github.com/bytecodealliance/wasmtime-go](https://pkg.go.dev/github.com/bytecodealliance/wasmtime-go) |\n|   wazero    |  `wazero.Engine()`  | N/A       |                          [github.com/tetratelabs/wazero](https://wazero.io)                           |\n\n\nFor example, to switch the engine to wasmer, change [example/main.go](example/main.go) like below:\n```diff\n--- a/example/main.go\n+++ b/example/main.go\n@@ -7,7 +7,7 @@ import (\n        \"strings\"\n\n        \"github.com/wapc/wapc-go\"\n-       \"github.com/wapc/wapc-go/engines/wazero\"\n+       \"github.com/wapc/wapc-go/engines/wasmer\"\n )\n\n func main() {\n@@ -22,7 +22,7 @@ func main() {\n                panic(err)\n        }\n\n-       engine := wazero.Engine()\n+       engine := wasmer.Engine()\n\n        module, err := engine.New(ctx, code, hostCall)\n        if err != nil {\n```\n\nThen, run with its build tag:\n```bash\n$ go run --tags wasmer example/main.go waPC!\nhello called\nHello, WaPC!\n```\n\n### Differences with [wapc-rs](https://github.com/wapc/wapc-rs) (Rust)\n\nBesides engine choices, there differences between this library and the Rust implementation:\n* Separate compilation (`New`) and instantiation (`Instantiate`) steps. This is to incur the cost of compilation once in a multi-instance scenario.\n* `Pool` for creating a pool of instances for a given Module.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwapc%2Fwapc-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwapc%2Fwapc-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwapc%2Fwapc-go/lists"}