wasmhttp

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 9 Imported by: 0

README

wasmhttp

Interop between Go net/http package and the fetch event handler in ServiceWorkers.

Documentation

Rendered for js/wasm

Overview

Package wasmhttp provides interop between the Request and Response objects in JavaScript with their counterparts in net/http. This is useful when building ServiceWorkers in Go which handle the fetch event.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandlerToFetch

func HandlerToFetch(handler http.Handler) func(js.Value, []js.Value) any

HandlerToFetch returns a fetch compatible function that serves HTTP requests using http.Handler.

func HeaderFromJS

func HeaderFromJS(value js.Value) http.Header

HeaderFromJS converts a JavaScript Headers object to a http.Header.

func HeaderToJS

func HeaderToJS(headers http.Header) js.Value

HeaderToJS converts a http.Header to a js.Value compatible with fetch headers.

func NewReader

func NewReader(r js.Value) io.ReadCloser

NewReader makes a io.ReadCloser from a JavaScript ReadableStream.

func RequestFromJS

func RequestFromJS(value js.Value) (*http.Request, error)

RequestFromJS converts a JavaScript request object into a http.Request.

Types

type Response

type Response interface {
	http.ResponseWriter
	http.Flusher
	io.Closer
}

func NewBufferedResponse

func NewBufferedResponse() (Response, js.Value)

NewBufferedResponse returns a Reponse which implements a http.ResponseWriter, and a corresponding js.Value which is a Promise that resolves to a JavaScript Response.

Jump to

Keyboard shortcuts

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