storage

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrQuotaExceeded = errors.New("storage quota exceeded")
	ErrUnauthorized  = errors.New("invalid edit secret")
	ErrExpired       = errors.New("stored item expired")
	ErrCorrupt       = errors.New("stored item is corrupt")
	ErrConflict      = errors.New("stored item revision conflict")
)
View Source
var DataDir = util.GetEnv("DATA_DIR", "./data")

DataDir is the filesystem path where stored items live.

View Source
var GlobalCache = &PasteCache{Items: make(map[string]models.CachedPaste)}

GlobalCache is the process paste index.

View Source
var GlobalDiffCache = &DiffCache{Items: make(map[string]models.CachedDiff)}

GlobalDiffCache is the process diff index.

Functions

func CreateDiff

func CreateDiff(title, base, compare, baseContent, compareContent string) (string, error)

CreateDiff creates a diff through the backward-compatible API.

func CreateDiffWithOptions added in v1.4.0

func CreateDiffWithOptions(title, base, compare, baseContent, compareContent string, options CreateOptions) (string, string, error)

CreateDiffWithOptions creates a diff and returns its one-time edit secret.

func CreatePaste

func CreatePaste(title, content, language string) (string, error)

CreatePaste creates a paste through the backward-compatible API.

func CreatePasteWithOptions added in v1.4.0

func CreatePasteWithOptions(title, content, language string, options CreateOptions) (string, string, error)

CreatePasteWithOptions creates a paste and returns its one-time edit secret.

func DeleteDiff

func DeleteDiff(id string) error

DeleteDiff deletes a diff through the backward-compatible API.

func DeleteDiffAuthorized added in v1.4.0

func DeleteDiffAuthorized(id, editSecret string) error

DeleteDiffAuthorized deletes a diff after edit-secret verification.

func DeleteDiffTrusted added in v1.4.0

func DeleteDiffTrusted(id string) error

DeleteDiffTrusted deletes a diff for an authenticated admin caller.

func DeletePaste

func DeletePaste(id string) error

DeletePaste deletes a paste through the backward-compatible API.

func DeletePasteAuthorized added in v1.4.0

func DeletePasteAuthorized(id, editSecret string) error

DeletePasteAuthorized deletes a paste after edit-secret verification.

func DeletePasteTrusted added in v1.4.0

func DeletePasteTrusted(id string) error

DeletePasteTrusted deletes a paste for an authenticated admin caller.

func ExportBackup added in v1.4.0

func ExportBackup(writer io.Writer) error

ExportBackup writes a verified tar archive to writer.

func FindDiffFile

func FindDiffFile(id string) (string, error)

FindDiffFile returns the stable JSON content path for a diff.

func FindPasteFile

func FindPasteFile(id string) (string, error)

FindPasteFile returns the stable content path for a paste.

func GetDiff

func GetDiff(id string) (models.CachedDiff, error)

GetDiff reads a diff. A burn-after-read diff is deleted after this read.

func GetItemMetadata added in v1.4.0

func GetItemMetadata(kind models.ItemKind, id string) (models.ItemMetadata, error)

GetItemMetadata returns one durable metadata document.

func GetPaste

func GetPaste(id string) (models.CachedPaste, error)

GetPaste reads a paste. A burn-after-read paste is deleted after this read.

func GetRawPaste

func GetRawPaste(id string) ([]byte, error)

GetRawPaste reads raw content and applies expiry and burn rules.

func ImportBackup added in v1.4.0

func ImportBackup(reader io.Reader, overwrite bool) error

ImportBackup merges a verified backup. Existing items require overwrite=true.

func Initialize added in v1.4.0

func Initialize() error

Initialize recovers interrupted mutations and verifies writable storage.

func ListDiffs

func ListDiffs() []models.DiffMeta

ListDiffs returns the first bounded diff page.

func ListPastes

func ListPastes() []models.PasteMeta

ListPastes returns the first bounded paste page.

func ListRevisions added in v1.4.0

func ListRevisions(kind models.ItemKind, id string) ([]models.RevisionInfo, error)

ListRevisions returns immutable snapshots in ascending revision order.

func LoadCacheFromDisk

func LoadCacheFromDisk()

LoadCacheFromDisk migrates legacy files and rebuilds the paste index.

func LoadDiffCacheFromDisk

func LoadDiffCacheFromDisk()

LoadDiffCacheFromDisk migrates legacy files and rebuilds the diff index.

func PurgeExpired added in v1.4.0

func PurgeExpired(now time.Time) (int, error)

PurgeExpired removes all expired pastes and diffs.

func RestoreBackup added in v1.4.0

func RestoreBackup(reader io.Reader) error

RestoreBackup atomically replaces the canonical item and revision trees.

func RestoreRevision added in v1.4.0

func RestoreRevision(kind models.ItemKind, id string, revision int64, editSecret string) error

RestoreRevision restores a snapshot as a new revision.

func RestoreRevisionExpected added in v1.4.0

func RestoreRevisionExpected(kind models.ItemKind, id string, revision int64, editSecret string, expectedRevision *int64) (int64, error)

RestoreRevisionExpected restores a snapshot when the current revision matches.

func RestoreRevisionTrusted added in v1.4.0

func RestoreRevisionTrusted(kind models.ItemKind, id string, revision int64) error

RestoreRevisionTrusted restores a snapshot for an authenticated admin caller.

func RestoreRevisionTrustedExpected added in v1.4.0

func RestoreRevisionTrustedExpected(kind models.ItemKind, id string, revision int64, expectedRevision *int64) (int64, error)

RestoreRevisionTrustedExpected restores a snapshot for an admin after a revision check.

func RestoreRevisionTrustedWithRevision added in v1.4.0

func RestoreRevisionTrustedWithRevision(kind models.ItemKind, id string, revision int64) (int64, error)

RestoreRevisionTrustedWithRevision restores a snapshot and returns the committed revision.

func RestoreRevisionWithRevision added in v1.4.0

func RestoreRevisionWithRevision(kind models.ItemKind, id string, revision int64, editSecret string) (int64, error)

RestoreRevisionWithRevision restores a snapshot and returns the committed revision.

func SearchDiffs

func SearchDiffs(query string) []models.DiffMeta

SearchDiffs returns the first bounded search page.

func SearchPastes

func SearchPastes(query string) []models.PasteMeta

SearchPastes returns the first bounded search page.

func SetStorageLimits added in v1.4.0

func SetStorageLimits(next StorageLimits)

SetStorageLimits replaces the storage limits. Non-positive values disable a limit.

func UpdateDiff added in v1.3.1

func UpdateDiff(id, title, base, compare, baseContent, compareContent string) error

UpdateDiff updates a diff through the backward-compatible API.

func UpdateDiffAuthorized added in v1.4.0

func UpdateDiffAuthorized(id, title, base, compare, baseContent, compareContent, editSecret string, patch MetadataPatch) error

UpdateDiffAuthorized updates a diff after edit-secret verification.

func UpdateDiffAuthorizedWithRevision added in v1.4.0

func UpdateDiffAuthorizedWithRevision(id, title, base, compare, baseContent, compareContent, editSecret string, patch MetadataPatch) (int64, error)

UpdateDiffAuthorizedWithRevision updates content and returns the committed revision.

func UpdateDiffTrusted added in v1.4.0

func UpdateDiffTrusted(id, title, base, compare, baseContent, compareContent string, patch MetadataPatch) error

UpdateDiffTrusted updates a diff for an authenticated admin caller.

func UpdateDiffTrustedWithRevision added in v1.4.0

func UpdateDiffTrustedWithRevision(id, title, base, compare, baseContent, compareContent string, patch MetadataPatch) (int64, error)

UpdateDiffTrustedWithRevision updates content and returns the committed revision.

func UpdateItemMetadata added in v1.4.0

func UpdateItemMetadata(kind models.ItemKind, id, editSecret string, patch MetadataPatch) error

UpdateItemMetadata changes metadata and creates a revision snapshot.

func UpdateItemMetadataTrusted added in v1.4.0

func UpdateItemMetadataTrusted(kind models.ItemKind, id string, patch MetadataPatch) error

UpdateItemMetadataTrusted changes metadata for an authenticated admin caller.

func UpdatePaste

func UpdatePaste(id, title, content, language string) error

UpdatePaste updates content through the backward-compatible API.

func UpdatePasteAuthorized added in v1.4.0

func UpdatePasteAuthorized(id, title, content, language, editSecret string, patch MetadataPatch) error

UpdatePasteAuthorized updates content after edit-secret verification.

func UpdatePasteAuthorizedWithRevision added in v1.4.0

func UpdatePasteAuthorizedWithRevision(id, title, content, language, editSecret string, patch MetadataPatch) (int64, error)

UpdatePasteAuthorizedWithRevision updates content and returns the committed revision.

func UpdatePasteTrusted added in v1.4.0

func UpdatePasteTrusted(id, title, content, language string, patch MetadataPatch) error

UpdatePasteTrusted updates a paste for an authenticated admin caller.

func UpdatePasteTrustedWithRevision added in v1.4.0

func UpdatePasteTrustedWithRevision(id, title, content, language string, patch MetadataPatch) (int64, error)

UpdatePasteTrustedWithRevision updates content and returns the committed revision.

func UsePaste added in v1.4.0

func UsePaste(id string, use func(models.CachedPaste) error) error

UsePaste reads one paste and commits burn deletion only after use succeeds.

func VerifyEditSecret added in v1.4.0

func VerifyEditSecret(kind models.ItemKind, id, secret string) (bool, error)

VerifyEditSecret checks the edit secret for one item.

Types

type BackupManifest added in v1.4.0

type BackupManifest struct {
	SchemaVersion int               `json:"schemaVersion"`
	CreatedAt     time.Time         `json:"createdAt"`
	Files         map[string]string `json:"files"`
}

BackupManifest describes every file in one portable backup.

type CreateOptions added in v1.4.0

type CreateOptions struct {
	EditSecret    string
	Tags          []string
	Favorite      bool
	ExpiresAt     *time.Time
	BurnAfterRead bool
}

CreateOptions configures durable metadata for a new item.

type DiffCache

type DiffCache struct {
	sync.RWMutex
	Items map[string]models.CachedDiff
}

DiffCache is the in-memory diff index.

type IntegrityIssue added in v1.4.0

type IntegrityIssue struct {
	Kind    models.ItemKind `json:"kind,omitempty"`
	ID      string          `json:"id,omitempty"`
	Path    string          `json:"path"`
	Problem string          `json:"problem"`
}

IntegrityIssue describes one corrupt or unsafe stored path.

type IntegrityReport added in v1.4.0

type IntegrityReport struct {
	Healthy   bool             `json:"healthy"`
	Items     int              `json:"items"`
	Revisions int              `json:"revisions"`
	Bytes     int64            `json:"bytes"`
	Issues    []IntegrityIssue `json:"issues"`
}

IntegrityReport summarizes a complete canonical storage scan.

func VerifyIntegrity added in v1.4.0

func VerifyIntegrity() IntegrityReport

VerifyIntegrity validates metadata, content, checksums, revisions, and paths.

type ItemFilter added in v1.4.0

type ItemFilter struct {
	Tag      string
	Favorite *bool
}

ItemFilter applies metadata filters before cursor pagination.

type MetadataPatch added in v1.4.0

type MetadataPatch struct {
	Tags             *[]string
	Favorite         *bool
	ExpiresAt        **time.Time
	BurnAfterRead    *bool
	ExpectedRevision *int64
}

MetadataPatch changes optional item metadata.

type Page added in v1.4.0

type Page[T any] struct {
	Items      []T    `json:"items"`
	NextCursor string `json:"nextCursor,omitempty"`
}

Page contains one stable cursor page.

func ListDiffsFilteredPage added in v1.4.0

func ListDiffsFilteredPage(filter ItemFilter, cursor string, limit int) (Page[models.DiffMeta], error)

ListDiffsFilteredPage filters metadata before applying the cursor.

func ListDiffsPage added in v1.4.0

func ListDiffsPage(cursor string, limit int) (Page[models.DiffMeta], error)

ListDiffsPage returns a stable cursor page sorted newest first.

func ListPastesFilteredPage added in v1.4.0

func ListPastesFilteredPage(filter ItemFilter, cursor string, limit int) (Page[models.PasteMeta], error)

ListPastesFilteredPage filters metadata before applying the cursor.

func ListPastesPage added in v1.4.0

func ListPastesPage(cursor string, limit int) (Page[models.PasteMeta], error)

ListPastesPage returns a stable cursor page sorted newest first.

func QueryDiffsPage added in v1.4.0

func QueryDiffsPage(query string, filter ItemFilter, cursor string, limit int) (Page[models.DiffMeta], error)

QueryDiffsPage applies search and metadata filters before pagination.

func QueryPastesPage added in v1.4.0

func QueryPastesPage(query string, filter ItemFilter, cursor string, limit int) (Page[models.PasteMeta], error)

QueryPastesPage applies search and metadata filters before pagination.

func SearchDiffsPage added in v1.4.0

func SearchDiffsPage(query, cursor string, limit int) (Page[models.DiffMeta], error)

SearchDiffsPage searches the bounded per-item search index.

func SearchPastesPage added in v1.4.0

func SearchPastesPage(query, cursor string, limit int) (Page[models.PasteMeta], error)

SearchPastesPage searches the bounded per-item search index.

type PasteCache

type PasteCache struct {
	sync.RWMutex
	Items map[string]models.CachedPaste
}

PasteCache is the in-memory paste index.

type Revision added in v1.4.0

type Revision struct {
	Metadata     models.ItemMetadata `json:"metadata"`
	PasteContent string              `json:"pasteContent,omitempty"`
	Diff         *models.DiffData    `json:"diff,omitempty"`
}

Revision contains decoded content for one immutable snapshot.

func GetRevision added in v1.4.0

func GetRevision(kind models.ItemKind, id string, revision int64) (Revision, error)

GetRevision returns one decoded revision and applies expiry and burn rules.

type StorageLimits added in v1.4.0

type StorageLimits struct {
	MaxTotalBytes         int64
	MaxItemBytes          int64
	MaxItems              int
	MaxSearchResults      int
	MaxSearchIndexBytes   int
	MaxCachedContentBytes int64
	MaxBackupBytes        int64
}

StorageLimits bounds storage and search work.

func GetStorageLimits added in v1.4.0

func GetStorageLimits() StorageLimits

GetStorageLimits returns a copy of the current storage limits.

Jump to

Keyboard shortcuts

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