You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# WebAssembly for Proxies (Go SDK) [](https://github.com/proxy-wasm/proxy-wasm-go-sdk/actions)[](LICENSE)
2
2
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.
5
5
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.
7
9
8
10
## Project Status
9
11
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.
11
16
12
17
## Getting Started
13
18
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.
16
23
17
24
## Requirements
18
25
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).
22
41
23
42
## Installation
24
43
@@ -28,7 +47,7 @@ go get github.com/proxy-wasm/proxy-wasm-go-sdk
28
47
29
48
## Minimal Example Plugin
30
49
31
-
A minimal plugin:
50
+
A minimal `main.go`plugin defining VM and Plugin contexts:
// pluginContext should implement OnPluginStart, NewHttpContext, NewTcpContext, etc
54
76
```
55
77
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
+
```
57
85
58
86
## Build and run Examples
59
87
@@ -63,7 +91,7 @@ make build.examples
63
91
64
92
# Build a specific example using the `go` tool.
65
93
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
67
95
68
96
# Test the built wasm module using `go test`.
69
97
go test
@@ -75,24 +103,32 @@ make run name=helloworld
75
103
76
104
## Compatible Envoy builds
77
105
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.
80
110
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.
82
113
83
114
## Build tags
84
115
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):
86
119
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.
88
123
89
124
## Contributing
90
125
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.
92
128
93
129
## External links
94
130
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