utils

package
v0.0.0-...-663eb47 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FastCaseInsensitiveStringCompare

func FastCaseInsensitiveStringCompare(a, b string) bool

FastCaseInsensitiveStringCompare compares two strings for equality, ignoring case sensitivity. It determines whether the strings are equivalent when case is disregarded, provided they have identical length. It returns true if they are considered equal under these conditions or false otherwise. This function is optimized for quick comparisons.

func GetPreviousTimePath

func GetPreviousTimePath(t time.Time) string

GetPreviousTimePath calculates the time one hour prior to a given time.Time and returns its path-like string representation formatted as "Year/Month/Day/Hour", where each component is zero-padded. This utility is often used for generating chronological identifiers for use in hierarchical structures like file paths or URLs.

func GetStructTag

func GetStructTag(f reflect.StructField, tagName string) string

GetStructTag retrieves the value associated with a given tag name from a struct field's tag. It takes a reflect.StructField and a string representing the tag name to search for. If the specified tag is not present, an empty string is returned.

func GetTimePath

func GetTimePath(t time.Time) string

GetTimePath converts a given time.Time to its string representation in the path-like format "Year/Month/Day/Hour". It ensures each component of the time is zero-padded for consistent length, facilitating the creation of hierarchical identifiers suitable for organizing data chronologically in filesystems or URLs.

func IsDirectory

func IsDirectory(path string) bool

func IsFile

func IsFile(path string) bool

IsFile determines whether the provided path refers to an existing regular file. It distinguishes between files and directories, returning true only for files. Non-existent paths or errors during file information retrieval result in a false outcome.

func NewCustomUUID

func NewCustomUUID() string

NewCustomUUID generates a new version 4 UUID as a string using a common custom generator to ensure the UUID is unique across different dimensions, such as spatial and temporal, which is essential for distributed systems that rely on identifiers being distinct and unrepeatable. It returns a string representation of the UUID.

func NewGoogleUUID

func NewGoogleUUID() string

NewGoogleUUID generates a new universally unique identifier (UUID) and returns it as a string. The UUID is designed to be sufficiently random to ensure uniqueness across different systems and over time, making it appropriate for use in various applications that require distinct string identifiers.

func NewKSUID

func NewKSUID() string

NewKSUID generates a globally unique identifier according to the KSUID specification and returns it as a string. The identifier incorporates a timestamp, making it suitable for applications that require time-ordered, unique IDs.

func NewPrefixedUUID

func NewPrefixedUUID(prefix string) string

NewPrefixedUUID combines a given prefix with a new UUID, separated by a hyphen, to produce a unique and identifiable string. The resulting string is useful where identifiers need to be both human-readable and globally unique.

func NewUUID

func NewUUID() string

NewUUID generates a universally unique identifier and returns it as a string, ensuring high randomness and uniqueness suitable for various systems and applications.

func SetFastKSUID

func SetFastKSUID()

SetFastKSUID configures the KSUID generator to use a faster, non-cryptographically secure source of randomness. It is suitable for use cases where identifier generation speed is prioritized over the cryptographic strength of the identifiers.

func SetSafeKSUID

func SetSafeKSUID()

SetSafeKSUID configures the KSUID package to utilize a source of randomness that is cryptographically secure for generating unique identifiers. This configuration is recommended for use cases where security considerations outweigh the need for fast identifier generation.

func StringInSlice

func StringInSlice(a string, list []string) bool

StringInSlice reports whether the provided string is present in the given slice of strings. It returns true if the string is found, otherwise false.

Types

This section is empty.

Jump to

Keyboard shortcuts

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