util

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: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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, error)

GenerateID creates a cryptographically random six-character identifier.

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) 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 accepts a legacy six-character ID or a secure 32-character ID. Every character must be alphanumeric to prevent path traversal.

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.

func NormalizeLanguage added in v1.4.0

func NormalizeLanguage(language string) string

NormalizeLanguage returns a supported language name or text.

func SanitizeTitle added in v1.4.0

func SanitizeTitle(title, fallback string) string

SanitizeTitle converts a title into a portable filename segment.

Types

This section is empty.

Jump to

Keyboard shortcuts

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