Documentation
¶
Index ¶
- Variables
- func CreateDiff(title, base, compare, baseContent, compareContent string) (string, error)
- func CreatePaste(title, content, language string) (string, error)
- func DeleteDiff(id string) error
- func DeletePaste(id string) error
- func FindDiffFile(id string) (string, error)
- func FindPasteFile(id string) (string, error)
- func GetDiff(id string) (models.CachedDiff, error)
- func GetPaste(id string) (models.CachedPaste, error)
- func GetRawPaste(id string) ([]byte, error)
- func ListDiffs() []models.DiffMeta
- func ListPastes() []models.PasteMeta
- func LoadCacheFromDisk()
- func LoadDiffCacheFromDisk()
- func SearchDiffs(query string) []models.DiffMeta
- func SearchPastes(query string) []models.PasteMeta
- func UpdateDiff(id, title, base, compare, baseContent, compareContent string) error
- func UpdatePaste(id, title, content, language string) error
- type DiffCache
- type PasteCache
Constants ¶
This section is empty.
Variables ¶
var DataDir = util.GetEnv("DATA_DIR", "/app/data")
DataDir is the filesystem path where paste files are stored.
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.
var GlobalDiffCache = &DiffCache{ Items: make(map[string]models.CachedDiff), }
GlobalDiffCache is the singleton in-memory search index for diffs.
Functions ¶
func CreateDiff ¶
CreateDiff creates a new diff file on disk and updates the in-memory cache.
func CreatePaste ¶
CreatePaste creates a new paste file on disk and updates the in-memory cache.
func DeletePaste ¶
DeletePaste removes the paste from disk and cache.
func FindDiffFile ¶
func FindPasteFile ¶
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 ¶
GetRawPaste reads the raw paste content directly from disk.
func ListPastes ¶
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 ¶
SearchDiffs returns diffs matching the query.
func SearchPastes ¶
SearchPastes returns pastes matching the query with contextual preview snippets.
func UpdateDiff ¶ added in v1.3.1
UpdateDiff overwrites an existing diff and updates the cache.
func UpdatePaste ¶
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.