nodejson

package
v0.16.397 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package nodejson writes JSON byte for byte as the previous runtime did (JavaScript's JSON.stringify) and gives an answer the ETag that runtime's dispatcher put on it, so a page's conditional request keeps working across the switch.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Answer

func Answer(r *http.Request, status int, v any, h http.Header) (int, any, http.Header)

Answer is a JSON route's answer the way the old dispatcher sent it: the ETag of the exact bytes, and 304 when the caller already holds them. The value is handed on as raw JSON.

func BodyUTF8

func BodyUTF8(r *http.Request) bool

BodyUTF8 says whether a request's body is text in UTF-8 as its content type names it (no charset, or utf-8): the previous dispatcher decoded any other charset, which ParseBody does not.

func ETag

func ETag(payload []byte) string

ETag is the old dispatcher's tag of a payload: a quoted, unpadded base64url SHA-1.

func Fresh

func Fresh(h http.Header, etag string) bool

Fresh says whether the request's If-None-Match already names the tag (the answer is then 304).

func Marshal

func Marshal(v any) []byte

Marshal encodes v as JSON.stringify would: no HTML escaping, U+2028 and U+2029 left as they are. Struct field order is the key order, so a struct must declare its fields in the order the old handler built its object. Strings must be valid UTF-8 (JavaScript strings had already replaced invalid bytes when they were read).

func ParseBody

func ParseBody(r *http.Request, limit int64, limitName string) (v any, raw string, status int, refusal string)

ParseBody reads a body as the previous dispatcher did before a handler ran: refused past limit (413, "Body exceeded <limitName> limit"), decoded as UTF-8 without a leading BOM, then JSON (empty is {}) for a JSON type, a form as an object, anything else as text. A refusal is a status and its text/plain body; raw is the decoded text.

Types

This section is empty.

Jump to

Keyboard shortcuts

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