workers

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 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().

Types

type Request

type Request struct {
	Method  string
	URL     string
	Headers map[string]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.

type Response

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

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

func (*Response) Header

func (w *Response) Header() map[string]string

Header returns the response headers map for setting values. Usage: w.Header()["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