util

package
v1.3.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TitleSanitizer *strings.Replacer

TitleSanitizer replaces characters in paste titles that could cause path traversal or filesystem issues, replacing them with safe alternatives.

Functions

func ExtToLang

func ExtToLang(ext string) string

ExtToLang converts a file extension (e.g. ".py") to a language name (e.g. "python"). Returns "text" if the extension is not recognized.

func GenerateID

func GenerateID() string

GenerateID creates a cryptographically random 6-character alphanumeric string suitable for use as a paste identifier. Uses crypto/rand to prevent ID prediction.

func GetEnv

func GetEnv(key, fallback string) string

GetEnv reads an environment variable or returns a fallback default.

func GetHighlightedPreview

func GetHighlightedPreview(content, query string, re *regexp.Regexp) string

GetHighlightedPreview returns a plain-text preview snippet centered around the first match of query. The frontend is responsible for highlighting.

func GetPreview

func GetPreview(content string) string

GetPreview returns a cleaned, truncated preview snippet of paste content for display in the sidebar. Returns plain text (no HTML escaping); the frontend is responsible for escaping before rendering.

func IsValidID

func IsValidID(id string) bool

IsValidID checks if the provided string contains only alphanumeric characters. This is used to validate IDs and prevent path traversal and globbing attacks.

func LangToExt

func LangToExt(lang string) string

LangToExt converts a language name (e.g. "python") to its file extension (e.g. ".py"). Returns ".txt" if the language is not recognized.

Types

This section is empty.

Jump to

Keyboard shortcuts

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