workers

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle

func Handle(fn func(*Response, *Request))

Handle registers fn as the single request handler and blocks forever. fn is called for every incoming HTTP request to the Worker. This must be called from main(); it never returns.

Uses the binding pattern from goflare/assets/worker.mjs:

binding.handleRequest is called per request with the JS Request object.
binding is accessed via js.Global().Get("context") — injected by wasm_exec.js Proxy.

func Ready

func Ready()

Ready signals the Workers runtime that Go initialization is complete. Called automatically by Handle(). Call manually only if not using Handle().

It reads the callback from context.binding — the same instance-scoped door Handle() uses — never from a bare global. js.Global() is a Proxy (assets/wasm_exec_worker.js) that resolves ONLY the "context" property per wasm instance; every other name resolves to the single object shared by the whole isolate, where a second request would silently clobber the signal. See assets/worker.mjs's start() for the JS side of this contract.

Types

type Request

type Request struct {
	Method string
	URL    string
	// contains filtered or unexported fields
}

Request represents an incoming HTTP request to the Worker.

func (*Request) Body

func (r *Request) Body() []byte

Body returns the raw request body bytes. It reads the body lazily on the first call.

func (*Request) Header

func (r *Request) Header(key string) string

Header returns the value of the named header, or "" if absent. Lookup is case-insensitive, per the Fetch Headers.get() contract — do not "fix" this by lowercasing key yourself; Headers.get() already does the right thing, and double-normalizing invites the exact bug this method replaces (see docs/PLAN.md at the time of this change: Headers.entries() lowercases names for iteration, but .get() matches case-insensitively — reading one as if it behaved like the other silently returned "" for every request).

type Response

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

Response is written by the handler and converted to a JS Response.

func (*Response) GetHeader added in v0.0.6

func (w *Response) GetHeader(key string) string

GetHeader returns a previously-set response header, or "" if absent.

func (*Response) SetHeader added in v0.0.6

func (w *Response) SetHeader(key, value string)

SetHeader sets a response header. Usage: w.SetHeader("Content-Type", "application/json")

func (*Response) Write

func (w *Response) Write(b []byte) (int, error)

Write appends bytes to the response body.

func (*Response) WriteHeader

func (w *Response) WriteHeader(code int)

WriteHeader sets the HTTP status code.

func (*Response) WriteString

func (w *Response) WriteString(s string) (int, error)

WriteString appends a string to the response body.

Jump to

Keyboard shortcuts

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