Help us shape the future of Go! Take the 2026 Go Developer Survey

dsutil

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package dsutil holds helpers shared by the docstore backends: argument validation, canonicalisation of document bodies and JSON encoding.

Index

Constants

View Source
const MaxSystemIDBytes = 1024

MaxSystemIDBytes bounds document ids in system collections.

Variables

This section is empty.

Functions

func Canonical

func Canonical(data map[string]any) (map[string]any, error)

Canonical returns a deep copy of a document body with reserved keys removed and every value converted to canonical JSON types (map[string]any, []any, float64, string, bool, nil). Values of other Go types are converted through encoding/json. Strings and keys are cleaned with docstore.CleanString and numbers with docstore.CleanNumber, and bodies nested deeper than docstore.MaxNestingDepth are rejected, so that every backend stores (and returns) exactly the same values; violations yield ErrInvalid. Nil values are kept (null data, or deletion markers in a patch).

func CheckKey

func CheckKey(site, collection, id string) error

CheckKey validates site, collection and document id. Ids in user collections must satisfy docstore.ValidateID. System collections (names starting with "_") are written by Backyard itself with ids such as e-mail addresses (the "_system/_users" cache), so there any valid UTF-8 id of 1 to MaxSystemIDBytes bytes without control characters is accepted.

func CheckNamespace

func CheckNamespace(site, collection string) error

CheckNamespace validates a site and collection (user or system collection).

func CheckWrite

func CheckWrite(site, collection, id, actor string) (string, error)

CheckWrite validates the key of a write like CheckKey and returns the actor in canonical form (see CleanActor).

func CleanActor

func CleanActor(actor string) (string, error)

CleanActor canonicalises the actor recorded in created_by/updated_by like any other stored string (see docstore.CleanString).

func DecodeData

func DecodeData(b []byte) (map[string]any, error)

DecodeData decodes a stored document body. Empty input yields an empty map.

func Marshal

func Marshal(data map[string]any) ([]byte, error)

Marshal encodes a canonical document body as compact JSON (HTML characters are not escaped).

func MergePatch

func MergePatch(data, patch map[string]any) (map[string]any, []byte, error)

MergePatch applies a canonical patch to stored data (shallow merge; nil deletes) and returns the merged body and its encoding.

func PreparePatch

func PreparePatch(patch map[string]any) (map[string]any, error)

PreparePatch canonicalises an Update patch (reserved keys dropped, nil values kept as deletion markers).

func PrepareWrite

func PrepareWrite(data map[string]any) (map[string]any, []byte, error)

PrepareWrite turns a Create/Put body into the stored form: reserved keys ("id", "_meta") are dropped, the body is deep-copied into canonical JSON types (map[string]any, []any, float64, string, bool, nil) and encoded.

func Unmarshal

func Unmarshal(b []byte, v any) error

Unmarshal decodes JSON into v using canonical types (numbers as float64).

Types

This section is empty.

Jump to

Keyboard shortcuts

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