storage

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DataDir = util.GetEnv("DATA_DIR", "/app/data")

DataDir is the filesystem path where paste files are stored.

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

GlobalCache is the singleton in-memory search index, populated at startup and kept in sync with every create/delete operation.

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

GlobalDiffCache is the singleton in-memory search index for diffs.

Functions

func CreateDiff

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

CreateDiff creates a new diff file on disk and updates the in-memory cache.

func CreatePaste

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

CreatePaste creates a new paste file on disk and updates the in-memory cache.

func DeleteDiff

func DeleteDiff(id string) error

DeleteDiff removes the diff from disk and cache.

func DeletePaste

func DeletePaste(id string) error

DeletePaste removes the paste from disk and cache.

func FindDiffFile

func FindDiffFile(id string) (string, error)

func FindPasteFile

func FindPasteFile(id string) (string, error)

FindPasteFile searches the data directory for a file matching the given ID prefix. It avoids filepath.Glob to prevent wildcard expansion vulnerabilities.

func GetDiff

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

GetDiff returns the cached diff data.

func GetPaste

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

GetPaste returns the cached paste data. If not in cache but on disk, it self-heals.

func GetRawPaste

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

GetRawPaste reads the raw paste content directly from disk.

func ListDiffs

func ListDiffs() []models.DiffMeta

ListDiffs returns a slice of all DiffMeta objects from the cache.

func ListPastes

func ListPastes() []models.PasteMeta

ListPastes returns a slice of all PasteMeta objects from the cache.

func LoadCacheFromDisk

func LoadCacheFromDisk()

LoadCacheFromDisk reads all paste files from the data directory into the in-memory cache. Called once on server startup to warm the search index.

func LoadDiffCacheFromDisk

func LoadDiffCacheFromDisk()

LoadDiffCacheFromDisk reads all diff files from the data/diffs directory.

func SearchDiffs

func SearchDiffs(query string) []models.DiffMeta

SearchDiffs returns diffs matching the query.

func SearchPastes

func SearchPastes(query string) []models.PasteMeta

SearchPastes returns pastes matching the query, highlighting the preview if necessary.

func UpdatePaste

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

UpdatePaste overwrites an existing paste and updates the cache.

Types

type DiffCache

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

DiffCache is a thread-safe in-memory index of all saved diffs.

type PasteCache

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

PasteCache is a thread-safe in-memory index of all paste content. It enables instant search without disk I/O on every query.

Jump to

Keyboard shortcuts

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