Documentation
¶
Index ¶
- Variables
- func CreateDiff(title, base, compare, baseContent, compareContent string) (string, error)
- func CreateDiffWithOptions(title, base, compare, baseContent, compareContent string, ...) (string, string, error)
- func CreatePaste(title, content, language string) (string, error)
- func CreatePasteWithOptions(title, content, language string, options CreateOptions) (string, string, error)
- func DeleteDiff(id string) error
- func DeleteDiffAuthorized(id, editSecret string) error
- func DeleteDiffTrusted(id string) error
- func DeletePaste(id string) error
- func DeletePasteAuthorized(id, editSecret string) error
- func DeletePasteTrusted(id string) error
- func ExportBackup(writer io.Writer) error
- func FindDiffFile(id string) (string, error)
- func FindPasteFile(id string) (string, error)
- func GetDiff(id string) (models.CachedDiff, error)
- func GetItemMetadata(kind models.ItemKind, id string) (models.ItemMetadata, error)
- func GetPaste(id string) (models.CachedPaste, error)
- func GetRawPaste(id string) ([]byte, error)
- func ImportBackup(reader io.Reader, overwrite bool) error
- func Initialize() error
- func ListDiffs() []models.DiffMeta
- func ListPastes() []models.PasteMeta
- func ListRevisions(kind models.ItemKind, id string) ([]models.RevisionInfo, error)
- func LoadCacheFromDisk()
- func LoadDiffCacheFromDisk()
- func PurgeExpired(now time.Time) (int, error)
- func RestoreBackup(reader io.Reader) error
- func RestoreRevision(kind models.ItemKind, id string, revision int64, editSecret string) error
- func RestoreRevisionExpected(kind models.ItemKind, id string, revision int64, editSecret string, ...) (int64, error)
- func RestoreRevisionTrusted(kind models.ItemKind, id string, revision int64) error
- func RestoreRevisionTrustedExpected(kind models.ItemKind, id string, revision int64, expectedRevision *int64) (int64, error)
- func RestoreRevisionTrustedWithRevision(kind models.ItemKind, id string, revision int64) (int64, error)
- func RestoreRevisionWithRevision(kind models.ItemKind, id string, revision int64, editSecret string) (int64, error)
- func SearchDiffs(query string) []models.DiffMeta
- func SearchPastes(query string) []models.PasteMeta
- func SetStorageLimits(next StorageLimits)
- func UpdateDiff(id, title, base, compare, baseContent, compareContent string) error
- func UpdateDiffAuthorized(id, title, base, compare, baseContent, compareContent, editSecret string, ...) error
- func UpdateDiffAuthorizedWithRevision(id, title, base, compare, baseContent, compareContent, editSecret string, ...) (int64, error)
- func UpdateDiffTrusted(id, title, base, compare, baseContent, compareContent string, ...) error
- func UpdateDiffTrustedWithRevision(id, title, base, compare, baseContent, compareContent string, ...) (int64, error)
- func UpdateItemMetadata(kind models.ItemKind, id, editSecret string, patch MetadataPatch) error
- func UpdateItemMetadataTrusted(kind models.ItemKind, id string, patch MetadataPatch) error
- func UpdatePaste(id, title, content, language string) error
- func UpdatePasteAuthorized(id, title, content, language, editSecret string, patch MetadataPatch) error
- func UpdatePasteAuthorizedWithRevision(id, title, content, language, editSecret string, patch MetadataPatch) (int64, error)
- func UpdatePasteTrusted(id, title, content, language string, patch MetadataPatch) error
- func UpdatePasteTrustedWithRevision(id, title, content, language string, patch MetadataPatch) (int64, error)
- func UsePaste(id string, use func(models.CachedPaste) error) error
- func VerifyEditSecret(kind models.ItemKind, id, secret string) (bool, error)
- type BackupManifest
- type CreateOptions
- type DiffCache
- type IntegrityIssue
- type IntegrityReport
- type ItemFilter
- type MetadataPatch
- type Page
- func ListDiffsFilteredPage(filter ItemFilter, cursor string, limit int) (Page[models.DiffMeta], error)
- func ListDiffsPage(cursor string, limit int) (Page[models.DiffMeta], error)
- func ListPastesFilteredPage(filter ItemFilter, cursor string, limit int) (Page[models.PasteMeta], error)
- func ListPastesPage(cursor string, limit int) (Page[models.PasteMeta], error)
- func QueryDiffsPage(query string, filter ItemFilter, cursor string, limit int) (Page[models.DiffMeta], error)
- func QueryPastesPage(query string, filter ItemFilter, cursor string, limit int) (Page[models.PasteMeta], error)
- func SearchDiffsPage(query, cursor string, limit int) (Page[models.DiffMeta], error)
- func SearchPastesPage(query, cursor string, limit int) (Page[models.PasteMeta], error)
- type PasteCache
- type Revision
- type StorageLimits
Constants ¶
This section is empty.
Variables ¶
var ( ErrQuotaExceeded = errors.New("storage quota exceeded") ErrExpired = errors.New("stored item expired") ErrCorrupt = errors.New("stored item is corrupt") ErrConflict = errors.New("stored item revision conflict") )
var DataDir = util.GetEnv("DATA_DIR", "./data")
DataDir is the filesystem path where stored items live.
var GlobalCache = &PasteCache{Items: make(map[string]models.CachedPaste)}
GlobalCache is the process paste index.
var GlobalDiffCache = &DiffCache{Items: make(map[string]models.CachedDiff)}
GlobalDiffCache is the process diff index.
Functions ¶
func CreateDiff ¶
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 ¶
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 ¶
DeleteDiff deletes a diff through the backward-compatible API.
func DeleteDiffAuthorized ¶ added in v1.4.0
DeleteDiffAuthorized deletes a diff after edit-secret verification.
func DeleteDiffTrusted ¶ added in v1.4.0
DeleteDiffTrusted deletes a diff for an authenticated admin caller.
func DeletePaste ¶
DeletePaste deletes a paste through the backward-compatible API.
func DeletePasteAuthorized ¶ added in v1.4.0
DeletePasteAuthorized deletes a paste after edit-secret verification.
func DeletePasteTrusted ¶ added in v1.4.0
DeletePasteTrusted deletes a paste for an authenticated admin caller.
func ExportBackup ¶ added in v1.4.0
ExportBackup writes a verified tar archive to writer.
func FindDiffFile ¶
FindDiffFile returns the stable JSON content path for a diff.
func FindPasteFile ¶
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
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 ¶
GetRawPaste reads raw content and applies expiry and burn rules.
func ImportBackup ¶ added in v1.4.0
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 ListPastes ¶
ListPastes returns the first bounded paste page.
func ListRevisions ¶ added in v1.4.0
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
PurgeExpired removes all expired pastes and diffs.
func RestoreBackup ¶ added in v1.4.0
RestoreBackup atomically replaces the canonical item and revision trees.
func RestoreRevision ¶ added in v1.4.0
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
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 ¶
SearchDiffs returns the first bounded search page.
func SearchPastes ¶
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
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 ¶
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.
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
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
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
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
SearchDiffsPage 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.
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.