web

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 15 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

View Source
var Crypto = true

Crypto is a truthy sentinel indicating crypto is always available in Go.

View Source
var Subtle = &CryptoSubtle{}

Subtle is the package-level SubtleCrypto singleton.

Functions

func Atob added in v0.5.0

func Atob(s string) string

Atob decodes a base64 string (Web API atob).

func Btoa added in v0.5.0

func Btoa(s string) string

Btoa encodes a string to base64 (Web API btoa).

Types

type CryptoKey added in v0.5.0

type CryptoKey struct {
	Algorithm string
	Key       []byte
}

CryptoKey holds key material for Web Crypto API operations.

type CryptoSubtle added in v0.5.0

type CryptoSubtle struct{}

CryptoSubtle implements a subset of the Web Crypto API (SubtleCrypto).

func (*CryptoSubtle) Digest added in v0.5.0

func (c *CryptoSubtle) Digest(algorithm any, data any) *promise.Promise[[]byte]

func (*CryptoSubtle) ImportKey added in v0.5.0

func (c *CryptoSubtle) ImportKey(format string, keyData any, algorithm any, extractable bool, keyUsages []string) *promise.Promise[any]

func (*CryptoSubtle) Sign added in v0.5.0

func (c *CryptoSubtle) Sign(algorithm any, key any, data any) *promise.Promise[[]byte]

func (*CryptoSubtle) Verify added in v0.5.0

func (c *CryptoSubtle) Verify(algorithm any, key any, signature any, data any) *promise.Promise[bool]

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 ...any) *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() [][]any

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
	BodyUsed       bool
	Cache          string
	Credentials    string
	Integrity      string
	Keepalive      bool
	Mode           string
	Redirect       string
	Referrer       string
	ReferrerPolicy string
	Signal         any
}

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

Clone creates a copy of the 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) Json added in v0.5.0

func (r *Request) Json() any

Json is an alias for JSON (used by transpiler's PascalCase convention).

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) ArrayBuffer added in v0.5.0

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

ArrayBuffer returns the response body as a byte slice.

func (*Response) Blob added in v0.5.0

func (r *Response) Blob() any

Blob returns the response body as a byte slice (simplified).

func (*Response) Clone

func (r *Response) Clone() *Response

func (*Response) FormData added in v0.5.0

func (r *Response) FormData() *promise.Promise[*FormData]

FormData parses the response body as multipart form data.

func (*Response) JSON added in v0.5.0

func (r *Response) JSON() any

JSON parses the response body as JSON.

func (*Response) Json added in v0.5.0

func (r *Response) Json() any

Json is an alias for JSON (used by transpiler's PascalCase convention).

func (*Response) Text

func (r *Response) Text() string

type TextDecoder added in v0.5.0

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

TextDecoder provides TextDecoder.decode().

func NewTextDecoder added in v0.5.0

func NewTextDecoder(args ...string) *TextDecoder

func (*TextDecoder) Decode added in v0.5.0

func (d *TextDecoder) Decode(buf any) string

type TextEncoder

type TextEncoder struct{}

TextEncoder provides TextEncoder.encode().

func NewTextEncoder

func NewTextEncoder() *TextEncoder

func (*TextEncoder) Encode

func (e *TextEncoder) Encode(input any) []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