Skip to content

Commit 31445f3

Browse files
Merge pull request #195 from rellfy/main
Fix Go example
2 parents 3228cb2 + f6f7dc5 commit 31445f3

File tree

1 file changed

+4
-11
lines changed
  • component-model/src/language-support

1 file changed

+4
-11
lines changed

component-model/src/language-support/go.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,14 @@ $ wkg wit build
4040
WIT package written to docs:[email protected]
4141
```
4242

43-
The `docs:[email protected]` file is a Wasm encoding of the WIT package. Next, we can generate the bindings for it:
44-
45-
```console
46-
$ go get go.bytecodealliance.org/cmd/wit-bindgen-go
47-
$ go run go.bytecodealliance.org/cmd/wit-bindgen-go generate -o internal/ ./docs:[email protected]
48-
```
49-
5043
Now, create your Go project:
5144

5245
```console
5346
$ mkdir add && cd add
5447
$ go mod init example.com
5548
```
5649

57-
Next, we can generate the bindings for the `add.wit` file:
50+
Next, we can generate the bindings for the Wasm component:
5851

5952
```console
6053
$ go get go.bytecodealliance.org/cmd/wit-bindgen-go
@@ -104,11 +97,11 @@ The `adder.exports.go` file contains the exported functions that need to be impl
10497
package main
10598

10699
import (
107-
"example.com/internal/example/component/example"
100+
"example.com/internal/docs/adder/adder"
108101
)
109102

110103
func init() {
111-
example.Exports.Add = func(x int32, y int32) int32 {
104+
adder.Exports.Add = func(x int32, y int32) int32 {
112105
return x + y
113106
}
114107
}
@@ -127,7 +120,7 @@ We can build our component using TinyGo by specifying the wit-package to be `add
127120
Under the hood, TinyGo invokes `wasm-tools` to embed the WIT file to the module and componentize it.
128121

129122
```console
130-
$ tinygo build -target=wasip2 -o add.wasm --wit-package add.wit --wit-world adder main.go
123+
$ tinygo build -target=wasip2 -o add.wasm --wit-package docs:[email protected] --wit-world adder main.go
131124
```
132125

133126
We now have an add component that satisfies our `adder` world, exporting the `add` function, which

0 commit comments

Comments
 (0)