web

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package web provides Go struct definitions for Web API types used by transpiled TypeScript code. These types mirror the Web API spec (Request, Response, Headers, URL, etc.) with Go-idiomatic field access and methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FormData

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

FormData is a simplified FormData representation.

func NewFormData

func NewFormData() *FormData

func (*FormData) Append

func (f *FormData) Append(name, value string)

func (*FormData) Await

func (f *FormData) Await() (*FormData, error)

Await is a no-op for sync types, providing compatibility when the transpiler emits await on a synchronous method (e.g., await request.formData() where Go FormData is sync).

func (*FormData) Delete

func (f *FormData) Delete(name string)

func (*FormData) ForEach

func (f *FormData) ForEach(fn func(value any, key string))

func (*FormData) Get

func (f *FormData) Get(name string) string

func (*FormData) Has

func (f *FormData) Has(name string) bool

func (*FormData) Set

func (f *FormData) Set(name, value string)

type Headers

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

Headers wraps http.Header with Web API-compatible methods.

func NewHeaders

func NewHeaders(init ...map[string]string) *Headers

func (*Headers) Append

func (h *Headers) Append(name, value string)

func (*Headers) Delete

func (h *Headers) Delete(name string)

func (*Headers) Entries

func (h *Headers) Entries() map[string]string

func (*Headers) ForEach

func (h *Headers) ForEach(fn func(value, key string))

func (*Headers) Get

func (h *Headers) Get(name string) string

func (*Headers) GetSetCookie

func (h *Headers) GetSetCookie() []string

func (*Headers) Has

func (h *Headers) Has(name string) bool

func (*Headers) Raw

func (h *Headers) Raw() http.Header

func (*Headers) Set

func (h *Headers) Set(name, value string)

type Request

type Request struct {
	Url     string
	Method  string
	Headers *Headers
	Body    io.Reader
}

Request represents a Web API Request.

func NewRequest

func NewRequest(urlStr string, init ...map[string]any) *Request

func (*Request) ArrayBuffer

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

ArrayBuffer returns the request body as bytes.

func (*Request) Blob

func (r *Request) Blob() any

Blob returns the request body as a Blob (simplified).

func (*Request) Clone

func (r *Request) Clone() *Request

func (*Request) FormData

func (r *Request) FormData() *FormData

FormData returns the request body parsed as FormData.

func (*Request) JSON

func (r *Request) JSON() any

JSON parses the request body as JSON.

func (*Request) Text

func (r *Request) Text() string

Text returns the request body as a string.

type Response

type Response struct {
	Body       io.Reader
	Headers    *Headers
	Status     int
	StatusText string
	Ok         bool
	// contains filtered or unexported fields
}

Response represents a Web API Response.

func NewResponse

func NewResponse(body any, init ...any) *Response

func ResponseJSON

func ResponseJSON(data any, status ...int) *Response

ResponseJSON creates a JSON response.

func ResponseRedirect

func ResponseRedirect(url string, status ...int) *Response

ResponseRedirect creates a redirect response.

func (*Response) Clone

func (r *Response) Clone() *Response

func (*Response) Text

func (r *Response) Text() string

type TextEncoder

type TextEncoder struct{}

TextEncoder provides TextEncoder.encode().

func NewTextEncoder

func NewTextEncoder() *TextEncoder

func (*TextEncoder) Encode

func (e *TextEncoder) Encode(s *string) []byte

type URL

type URL struct {
	Pathname string
	Search   string
	Hash     string
	Host     string
	Hostname string
	Port     string
	Protocol string
	Origin   string
	Href     string
}

URL represents the Web API URL.

func NewURL

func NewURL(rawURL string) *URL

Jump to

Keyboard shortcuts

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