wazero_net

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2024 License: MIT Imports: 21 Imported by: 0

README

WAZERO NET

this project provider net/http for wazero, it not belong to wazero's official project

note: unsupport tinygo, because tinygo's gc has some problem for wasm

Dial's Conn can not convert to net.TCPConn,net.UDPConn

Install

go get github.com/labulakalia/wazero_net

Example

must use go version >= go1.24, because go1.24 will support go:wasmexport directive to export function

Install Required Go Version

go install golang.org/dl/go1.24rc1@latest
go1.24rc1 download
cd example
GOOS=wasip1 GOARCH=wasm go1.24rc1 build -buildmode=c-shared -o http.wasm http.go
GOOS=wasip1 GOARCH=wasm go1.24rc1 build -buildmode=c-shared -o net.wasm net.go
go1.24rc1 run example.go

Todo

  • support listen ip
  • add unit test

Some Limit or Bug

sleep sleep2 need call on multi goroutine syscall, or goroutinue can no scheduler,this is bug example code

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitFuncExport

func InitFuncExport(r wazero.Runtime) wazero.HostModuleBuilder

func ReadBytes

func ReadBytes(m api.Module, offset, byteCount uint32) ([]byte, error)

Types

type HostNet

type HostNet struct {
	// contains filtered or unexported fields
}

type Request

type Request struct {
	Method string

	URL *url.URL

	Proto      string // "HTTP/1.0"
	ProtoMajor int    // 1
	ProtoMinor int    // 0

	Header http.Header

	Body []byte

	ContentLength int64

	TransferEncoding []string

	Close bool

	Host string

	Form url.Values

	PostForm url.Values

	MultipartForm *multipart.Form

	RemoteAddr string

	RequestURI string

	Pattern string
}

func (*Request) ParseHttpRequest

func (r *Request) ParseHttpRequest(req *http.Request) error

func (*Request) ToHttpRequest

func (r *Request) ToHttpRequest() (req *http.Request)

type Response

type Response struct {
	StatusCode int    // e.g. 200
	Proto      string // e.g. "HTTP/1.0"
	ProtoMajor int    // e.g. 1
	ProtoMinor int    // e.g. 0

	Header http.Header

	Body []byte

	ContentLength int64
}

func (*Response) ToHttpResponse

func (r *Response) ToHttpResponse() *http.Response

Directories

Path Synopsis
wasi
net

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL