Skip to content

httpwasm/httpwasm-host-go

 
 

Repository files navigation

Build Go Report Card License

http-wasm Host Library for Go

http-wasm defines HTTP functions implemented in WebAssembly. This repository includes http_handler ABI middleware for various HTTP server libraries written in Go.

WARNING: This is an early draft

The current maturity phase is early draft. Once this is integrated with coraza and dapr, we can begin discussions about compatability.

个人理解

wasm/host处理流程

  • handler.Middleware作为包装器
type middleware struct {
	host            handler.Host // host实现
	runtime         wazero.Runtime // 运行时
	guestModule     wazero.CompiledModule //编译的模式
	moduleConfig    wazero.ModuleConfig //模块配置
	guestConfig     []byte // wasm二进制文件
	logger          api.Logger
	pool            sync.Pool
	features        handler.Features
	instanceCounter uint64
}
  • handler.Host接口增加函数
	// GetTemplate supports the WebAssembly function export FuncGetTemplate.
	GetTemplate(ctx context.Context) string

	// SetTemplate supports the WebAssembly function export FuncSetTemplate.
	SetTemplate(ctx context.Context, template string)
  • 默认空实现
func (UnimplementedHost) GetTemplate(context.Context) string { return "" }
func (UnimplementedHost) SetTemplate(context.Context, string) 
  • handler.middleware.go#692文件中,声明导入函数,这样在guest/wasm中就能调用了,都是通过指针地址进行数据交换的.
    //getTemplate
	NewFunctionBuilder().
	WithGoModuleFunction(wazeroapi.GoModuleFunc(m.getTemplate), []wazeroapi.ValueType{i32, i32}, []wazeroapi.ValueType{i32}).
	WithParameterNames("buf", "buf_limit").Export(handler.FuncGetTemplate).
	NewFunctionBuilder().
	//setTemplate
	WithGoModuleFunction(wazeroapi.GoModuleFunc(m.setTemplate), []wazeroapi.ValueType{i32, i32}, []wazeroapi.ValueType{}).
	WithParameterNames("template", "template_len").Export(handler.FuncSetTemplate).

About

HTTP middleware libraries implemented by http-wasm WebAssembly Guest modules

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 99.0%
  • Makefile 1.0%