util

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package util provides general-purpose utility functions.

Package util provides general-purpose utility functions including URL slug generation and validation with Unicode normalization support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsPathTraversal added in v0.1.0

func ContainsPathTraversal(path string) bool

ContainsPathTraversal checks if a path contains traversal sequences. Returns true if the path contains ".." after cleaning.

func IsValidAlias

func IsValidAlias(s string) bool

IsValidAlias checks if a string is a valid alias format. Aliases can contain path segments separated by forward slashes (e.g., "blog/post/55"). Each segment must be a valid slug: lowercase letters, numbers, and hyphens.

func IsValidLangCode added in v0.5.0

func IsValidLangCode(s string) bool

IsValidLangCode checks if a string is a valid language code format. Language codes are typically 2-3 letter codes optionally followed by a hyphen and a 2-4 letter region code (e.g., "en", "de", "zh-cn", "pt-br"). Only lowercase letters, digits, and hyphens are allowed.

func IsValidSlug

func IsValidSlug(s string) bool

IsValidSlug checks if a string is a valid slug format.

func NullInt64FromPtr

func NullInt64FromPtr(ptr *int64) sql.NullInt64

NullInt64FromPtr converts a pointer to int64 into sql.NullInt64. Returns a valid NullInt64 if the pointer is non-nil, otherwise returns an invalid one.

func NullInt64FromValue

func NullInt64FromValue(val int64) sql.NullInt64

NullInt64FromValue creates a valid sql.NullInt64 from an int64 value.

func NullStringFromPtr

func NullStringFromPtr(ptr *string) sql.NullString

NullStringFromPtr converts a pointer to string into sql.NullString. Returns a valid NullString if the pointer is non-nil, otherwise returns an invalid one.

func NullStringFromValue

func NullStringFromValue(s string) sql.NullString

NullStringFromValue creates a sql.NullString from a string value. Returns a valid NullString if the string is non-empty, otherwise returns an invalid one.

func ParseNullInt64

func ParseNullInt64(s string) sql.NullInt64

ParseNullInt64 parses a string into sql.NullInt64. Returns an invalid NullInt64 if the string is empty, "0", or cannot be parsed.

func ParseNullInt64Positive

func ParseNullInt64Positive(s string) sql.NullInt64

ParseNullInt64Positive parses a string into sql.NullInt64, requiring positive values. Returns an invalid NullInt64 if the string is empty, cannot be parsed, or value is <= 0.

func SafeJoinPath added in v0.1.0

func SafeJoinPath(basePath string, components ...string) (string, error)

SafeJoinPath joins path components and validates the result is within the base directory. Returns the cleaned path or an error if traversal is detected.

func SanitizeFilename added in v0.1.0

func SanitizeFilename(filename string) (string, error)

SanitizeFilename extracts only the base filename, removing any directory components. This prevents path traversal attacks via filenames like "../../../etc/passwd". Returns an error if the filename is invalid.

func Slugify

func Slugify(s string) string

Slugify converts a string to a URL-friendly ASCII slug. Non-ASCII characters (Cyrillic, CJK, etc.) are transliterated to their closest ASCII equivalent. Accents are removed, spaces become hyphens, and only alphanumeric characters and hyphens are kept.

func ValidatePathWithinBase added in v0.1.0

func ValidatePathWithinBase(basePath, targetPath string) error

ValidatePathWithinBase ensures that a resolved path is within the expected base directory. It cleans both paths and checks that the resolved path starts with the base path. Returns an error if path traversal is detected.

Types

This section is empty.

Jump to

Keyboard shortcuts

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