sidecar

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package sidecar reads and writes the metadata file that `cflio read` leaves next to a downloaded page body. The sidecar is what makes `update` self-describing: the page it targets, the profile it authenticates with and the version it locks against all come from here, so there is no way to write to a page that was never read.

Index

Constants

View Source
const Suffix = ".meta.json"

Suffix is appended to the body file's path to get the sidecar's path.

Variables

This section is empty.

Functions

func Path

func Path(bodyPath string) string

Path returns the sidecar path for a body file.

func Remove

func Remove(bodyPath string) error

Remove deletes the sidecar next to bodyPath if one exists. A missing sidecar is not an error, so callers can use this to guarantee that no stale metadata survives alongside a body they are about to replace.

func Write

func Write(bodyPath string, meta Meta) error

Write creates or replaces the sidecar next to bodyPath.

Types

type Meta

type Meta struct {
	PageID  string `json:"page_id"`
	Version int    `json:"version"`
	Title   string `json:"title"`
	Status  string `json:"status"`
	PageURL string `json:"page_url"`
	// Subtype is the page's v2 subtype — "live" for a live doc, empty for a
	// classic page. It is a pointer, and the one optional field, because
	// three states have to be told apart: a sidecar written before cflio
	// recorded it (nil, the key absent), a page the API reported no subtype
	// for (empty, the key present), and a live doc. A plain string would
	// collapse the first two, and they call for opposite answers — one is a
	// reason to ask for a fresh read, the other is a settled "not a live
	// doc". Nothing requires it: a sidecar already on disk has to keep
	// working with `update`.
	Subtype *string `json:"subtype,omitempty"`
}

Meta is the sidecar's contents. Every field but Subtype is required: page ID and version drive the optimistic lock, title and status are mandatory in the update payload, and the page URL is what selects the profile.

func Load

func Load(bodyPath string) (Meta, error)

Load reads and validates the sidecar next to bodyPath.

func (Meta) LiveDoc

func (m Meta) LiveDoc() (live, known bool)

LiveDoc reports whether the page is a live doc, and whether the sidecar knows: a sidecar written before cflio recorded the subtype answers known = false, which is a different thing from "not a live doc" and calls for a different answer — ask for a fresh read rather than act on a guess.

Jump to

Keyboard shortcuts

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