The Go SDK for Proxy-Wasm, enabling developers to write Proxy-Wasm plugins in Go.
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.
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. This SDK relies on the new WASI Reactors support in Go 1.24. It's been tested and used in production by customers on Google Cloud Platform's Service Extensions platform, so give it a whirl!
go get github.com/proxy-wasm/proxy-wasm-go-sdk
A minimal main.go plugin defining VM and Plugin contexts:
package main
import (
"github.com/proxy-wasm/proxy-wasm-go-sdk/proxywasm"
"github.com/proxy-wasm/proxy-wasm-go-sdk/proxywasm/types"
)
func main() {}
func init() {
// Plugin authors can use any one of four entrypoints, such as
// `proxywasm.SetVMContext`, `proxywasm.SetPluginContext`, or
// `proxywasm.SetTcpContext`.
proxywasm.SetHttpContext(func(contextID uint32) types.HttpContext {
return &httpContext{}
})
}
type httpContext struct {
types.DefaultHttpContext
}
func (*httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
proxywasm.LogInfo("Hello, world!")
return types.ActionContinue
}
Compile the plugin as follows:
$ go mod init main.go
$ go mod tidy
$ env GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o my-plugin.wasm main.go
# Build all examples.
make build.examples
# Build a specific example using the `go` tool.
cd examples/helloworld
env GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o main.wasm main.go
# Test the built wasm module using `go test`.
go test
# Build and test a specific example from the repo root using `make`.
make build.example name=helloworld
make run name=helloworld
Envoy is the first host side implementation of Proxy-Wasm ABI, and we run end-to-end tests with multiple versions of Envoy and Envoy-based istio/proxy in order to verify Proxy-Wasm Go SDK works as expected.
Please refer to workflow.yaml for which version is used for End-to-End tests.
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:
proxywasm_timing: Enables logging of time spent in invocation of the
plugin's exported functions. This can be useful for debugging performance
issues.We welcome contributions from the community! See CONTRIBUTING.md for how to contribute to this repository.
(top 30 of 33)
Go
99.5%
The Go SDK for Proxy-Wasm, enabling developers to write Proxy-Wasm plugins in Go.
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.
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. This SDK relies on the new WASI Reactors support in Go 1.24. It's been tested and used in production by customers on Google Cloud Platform's Service Extensions platform, so give it a whirl!
go get github.com/proxy-wasm/proxy-wasm-go-sdk
A minimal main.go plugin defining VM and Plugin contexts:
package main
import (
"github.com/proxy-wasm/proxy-wasm-go-sdk/proxywasm"
"github.com/proxy-wasm/proxy-wasm-go-sdk/proxywasm/types"
)
func main() {}
func init() {
// Plugin authors can use any one of four entrypoints, such as
// `proxywasm.SetVMContext`, `proxywasm.SetPluginContext`, or
// `proxywasm.SetTcpContext`.
proxywasm.SetHttpContext(func(contextID uint32) types.HttpContext {
return &httpContext{}
})
}
type httpContext struct {
types.DefaultHttpContext
}
func (*httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
proxywasm.LogInfo("Hello, world!")
return types.ActionContinue
}
Compile the plugin as follows:
$ go mod init main.go
$ go mod tidy
$ env GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o my-plugin.wasm main.go
# Build all examples.
make build.examples
# Build a specific example using the `go` tool.
cd examples/helloworld
env GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o main.wasm main.go
# Test the built wasm module using `go test`.
go test
# Build and test a specific example from the repo root using `make`.
make build.example name=helloworld
make run name=helloworld
Envoy is the first host side implementation of Proxy-Wasm ABI, and we run end-to-end tests with multiple versions of Envoy and Envoy-based istio/proxy in order to verify Proxy-Wasm Go SDK works as expected.
Please refer to workflow.yaml for which version is used for End-to-End tests.
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:
proxywasm_timing: Enables logging of time spent in invocation of the
plugin's exported functions. This can be useful for debugging performance
issues.We welcome contributions from the community! See CONTRIBUTING.md for how to contribute to this repository.
(top 30 of 33)
Go
99.5%