Skip to content

Commit 23e5db5

Browse files
authored
Fix the README sample plugin code and build steps (#3)
Signed-off-by: Martijn Stevenson <[email protected]>
1 parent fa61e04 commit 23e5db5

File tree

1 file changed

+62
-26
lines changed

1 file changed

+62
-26
lines changed

README.md

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
11
# WebAssembly for Proxies (Go SDK) [![Build](https://github.com/proxy-wasm/proxy-wasm-go-sdk/actions/workflows/workflow.yaml/badge.svg)](https://github.com/proxy-wasm/proxy-wasm-go-sdk/actions) [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
22

3-
The Go SDK for
4-
[Proxy-Wasm](https://github.com/proxy-wasm/spec), enabling developers to write Proxy-Wasm plugins in Go.
3+
The Go SDK for [Proxy-Wasm](https://github.com/proxy-wasm/spec), enabling
4+
developers to write Proxy-Wasm plugins in Go.
55

6-
Note: This SDK targets the upstream Go compiler, version 1.24 or later. This is different than the forked github.com/tetratelabs/proxy-wasm-go-sdk, which targets the TinyGo compiler.
6+
Note: This SDK targets the upstream Go compiler, version 1.24 or later. This is
7+
different than the forked github.com/tetratelabs/proxy-wasm-go-sdk, which
8+
targets the TinyGo compiler.
79

810
## Project Status
911

10-
This SDK is based off of github.com/tetratelabs/proxy-wasm-go-sdk; however, it is effectively a new SDK targeting a completely different toolchain. It relies on the not-yet-released Go 1.24 and hasn't seen extensive prod testing by end-users. This SDK is an alpha product.
12+
This SDK is based off of github.com/tetratelabs/proxy-wasm-go-sdk; however, it
13+
is effectively a new SDK targeting a completely different toolchain. It relies
14+
on the not-yet-released Go 1.24 and hasn't seen extensive prod testing by
15+
end-users. This SDK is an alpha product.
1116

1217
## Getting Started
1318

14-
- [examples](examples) directory contains the example codes on top of this SDK.
15-
- [OVERVIEW.md](doc/OVERVIEW.md) the overview of Proxy-Wasm, the API of this SDK, and the things you should know when writing plugins.
19+
- [examples](examples) directory contains the example codes on top of this
20+
SDK.
21+
- [OVERVIEW.md](doc/OVERVIEW.md) the overview of Proxy-Wasm, the API of this
22+
SDK, and the things you should know when writing plugins.
1623

1724
## Requirements
1825

19-
- \[Required] [Go](https://go.dev/): v1.24+ - This SDK leverages Go 1.24's support for [WASI](https://github.com/WebAssembly/WASI) (WebAssembly System Interface) reactors. You can grab a release candidate from the [Go unstable releases page](https://go.dev/dl/#unstable). A stable release of Go 1.24 is [expected in February 2025](https://tip.golang.org/doc/go1.24).
20-
- \[Required] A host environment supporting this toolchain - This SDK leverages additional host imports added to the proxy-wasm-cpp-host in [PR#427](https://github.com/proxy-wasm/proxy-wasm-cpp-host/pull/427). This has yet to be merged, let alone make its way downstream to Envoy, ATS, nginx, or managed environments.
21-
- \[Optional] [Envoy](https://www.envoyproxy.io) - To run end-to-end tests, you need to have an Envoy binary. You can use [func-e](https://func-e.io) as an easy way to get started with Envoy or follow [the official instruction](https://www.envoyproxy.io/docs/envoy/latest/start/install).
26+
- \[Required] [Go](https://go.dev/): v1.24+ - This SDK leverages Go 1.24's
27+
support for [WASI](https://github.com/WebAssembly/WASI) (WebAssembly System
28+
Interface) reactors. You can grab a release candidate from the
29+
[Go unstable releases page](https://go.dev/dl/#unstable). A stable release
30+
of Go 1.24 is
31+
[expected in February 2025](https://tip.golang.org/doc/go1.24).
32+
- \[Required] A host environment supporting this toolchain - This SDK
33+
leverages additional host imports added to the proxy-wasm-cpp-host in
34+
[PR#427](https://github.com/proxy-wasm/proxy-wasm-cpp-host/pull/427). This
35+
has yet to be merged, let alone make its way downstream to Envoy, ATS,
36+
nginx, or managed environments.
37+
- \[Optional] [Envoy](https://www.envoyproxy.io) - To run end-to-end tests,
38+
you need to have an Envoy binary. You can use [func-e](https://func-e.io) as
39+
an easy way to get started with Envoy or follow
40+
[the official instruction](https://www.envoyproxy.io/docs/envoy/latest/start/install).
2241

2342
## Installation
2443

@@ -28,7 +47,7 @@ go get github.com/proxy-wasm/proxy-wasm-go-sdk
2847

2948
## Minimal Example Plugin
3049

31-
A minimal plugin:
50+
A minimal `main.go` plugin defining VM and Plugin contexts:
3251

3352
```go
3453
package main
@@ -38,22 +57,31 @@ import (
3857
"github.com/proxy-wasm/proxy-wasm-go-sdk/proxywasm/types"
3958
)
4059

60+
func main() {}
4161
func init() {
4262
proxywasm.SetVMContext(&vmContext{})
4363
}
64+
4465
type vmContext struct {
4566
types.DefaultVMContext
4667
}
68+
func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext {
69+
return &pluginContext{}
70+
}
71+
4772
type pluginContext struct {
4873
types.DefaultPluginContext
4974
}
50-
func (*context) NewPluginContext(contextID uint32) types.PluginContext {
51-
return &context{}
52-
}
53-
func main() {}
75+
// pluginContext should implement OnPluginStart, NewHttpContext, NewTcpContext, etc
5476
```
5577

56-
It can be compiled with `env GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o my-plugin.wasm main.go`.
78+
Compile the plugin as follows:
79+
80+
```bash
81+
$ go mod init main.go
82+
$ go mod tidy
83+
$ env GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o my-plugin.wasm main.go
84+
```
5785

5886
## Build and run Examples
5987

@@ -63,7 +91,7 @@ make build.examples
6391

6492
# Build a specific example using the `go` tool.
6593
cd examples/helloworld
66-
env GOOS=wasp1 GOARCH=wasm go build -buildmode=c-shared -o main.wasm main.go
94+
env GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o main.wasm main.go
6795

6896
# Test the built wasm module using `go test`.
6997
go test
@@ -75,24 +103,32 @@ make run name=helloworld
75103

76104
## Compatible Envoy builds
77105

78-
Envoy is the first host side implementation of Proxy-Wasm ABI,
79-
and we run end-to-end tests with multiple versions of Envoy and Envoy-based [istio/proxy](https://github.com/istio/proxy) in order to verify Proxy-Wasm Go SDK works as expected.
106+
Envoy is the first host side implementation of Proxy-Wasm ABI, and we run
107+
end-to-end tests with multiple versions of Envoy and Envoy-based
108+
[istio/proxy](https://github.com/istio/proxy) in order to verify Proxy-Wasm Go
109+
SDK works as expected.
80110

81-
Please refer to [workflow.yaml](.github/workflows/workflow.yaml) for which version is used for End-to-End tests.
111+
Please refer to [workflow.yaml](.github/workflows/workflow.yaml) for which
112+
version is used for End-to-End tests.
82113

83114
## Build tags
84115

85-
The following build tags can be used to customize the behavior of the built plugin. Build tags [can be specified in the `go build` command via the `-tags` flag](https://pkg.go.dev/cmd/go#:~:text=tags):
116+
The following build tags can be used to customize the behavior of the built
117+
plugin. Build tags
118+
[can be specified in the `go build` command via the `-tags` flag](https://pkg.go.dev/cmd/go#:~:text=tags):
86119

87-
- `proxywasm_timing`: Enables logging of time spent in invocation of the plugin's exported functions. This can be useful for debugging performance issues.
120+
- `proxywasm_timing`: Enables logging of time spent in invocation of the
121+
plugin's exported functions. This can be useful for debugging performance
122+
issues.
88123

89124
## Contributing
90125

91-
We welcome contributions from the community! See [CONTRIBUTING.md](doc/CONTRIBUTING.md) for how to contribute to this repository.
126+
We welcome contributions from the community! See
127+
[CONTRIBUTING.md](doc/CONTRIBUTING.md) for how to contribute to this repository.
92128

93129
## External links
94130

95-
- [WebAssembly for Proxies (ABI specification)](https://github.com/proxy-wasm/spec)
96-
- [WebAssembly for Proxies (C++ SDK)](https://github.com/proxy-wasm/proxy-wasm-cpp-sdk)
97-
- [WebAssembly for Proxies (Rust SDK)](https://github.com/proxy-wasm/proxy-wasm-rust-sdk)
98-
- [WebAssembly for Proxies (AssemblyScript SDK)](https://github.com/solo-io/proxy-runtime)
131+
- [WebAssembly for Proxies (ABI specification)](https://github.com/proxy-wasm/spec)
132+
- [WebAssembly for Proxies (C++ SDK)](https://github.com/proxy-wasm/proxy-wasm-cpp-sdk)
133+
- [WebAssembly for Proxies (Rust SDK)](https://github.com/proxy-wasm/proxy-wasm-rust-sdk)
134+
- [WebAssembly for Proxies (AssemblyScript SDK)](https://github.com/solo-io/proxy-runtime)

0 commit comments

Comments
 (0)