Currently, the example points users the wrong way as no SDK is maintaining 0.1 anymore. Is it ok if I change it to something maintained? Ex tinygo with 0.2?
cc @taoyuanyuan @antJack
Ex. here's the current plugin used in tests ported to a currently maintained SDK in go
package main
import (
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"
)
// build main with `tinygo build -o main.wasm -scheduler=none -target=wasi ./main.go`
func main() {
proxywasm.SetVMContext(&vmContext{})
}
type vmContext struct {
// Embed the default VM context here,
// so that we don't need to reimplement all the methods.
types.DefaultVMContext
}
// NewPluginContext overrides types.DefaultVMContext.
func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext {
return &pluginContext{}
}
type pluginContext struct {
// Embed the default plugin context here,
// so that we don't need to reimplement all the methods.
types.DefaultPluginContext
}
// NewHttpContext overrides types.DefaultPluginContext.
func (*pluginContext) NewHttpContext(contextID uint32) types.HttpContext {
return &httpHeaders{contextID: contextID}
}
type httpHeaders struct {
// Embed the default http context here,
// so that we don't need to reimplement all the methods.
types.DefaultHttpContext
contextID uint32
}
// OnHttpRequestHeaders overrides types.DefaultHttpContext.
func (ctx *httpHeaders) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
proxywasm.LogDebugf("print from wasm, onRequestHeaders, context id: %d", ctx.contextID)
hs, err := proxywasm.GetHttpRequestHeaders()
if err != nil {
proxywasm.LogCriticalf("failed to get request headers: %v", err)
}
for _, h := range hs {
proxywasm.LogInfof("print from wasm, %s -> %s", h[0], h[1])
}
return types.ActionContinue
}