utils

package module
v0.0.0-...-9e38f01 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StringUtilsInstance     = NewStringUtils()
	ValidationUtilsInstance = NewValidationUtils()
	CryptoUtilsInstance     = NewCryptoUtils()
	TimeUtilsInstance       = NewTimeUtils()
	UUIDUtilsInstance       = NewUUIDUtils()
	FileUtilsInstance       = NewFileUtils()
)

Global utility instances for backward compatibility

Functions

func GenerateHash

func GenerateHash(input string) string

func GenerateUUID

func GenerateUUID() uuid.UUID

func GenerateUUIDString

func GenerateUUIDString() string

func HashPassword

func HashPassword(password string) (string, error)

func IsEmpty

func IsEmpty(s string) bool

Convenience functions

func IsNotEmpty

func IsNotEmpty(s string) bool

func IsValidEmail

func IsValidEmail(email string) bool

func IsValidPassword

func IsValidPassword(password string) bool

func IsValidPhone

func IsValidPhone(phone string) bool

func IsValidURL

func IsValidURL(url string) bool

func IsValidUUID

func IsValidUUID(uuidStr string) bool

func Now

func Now() time.Time

func NowUTC

func NowUTC() time.Time

func VerifyPassword

func VerifyPassword(password, hash string) bool

Types

type CryptoUtils

type CryptoUtils struct{}

CryptoUtils provides cryptographic utility functions

func NewCryptoUtils

func NewCryptoUtils() *CryptoUtils

NewCryptoUtils creates a new CryptoUtils instance

func (*CryptoUtils) GenerateHash

func (cu *CryptoUtils) GenerateHash(input string) string

GenerateHash generates a SHA256 hash of the input string

func (*CryptoUtils) GenerateRandomBytes

func (cu *CryptoUtils) GenerateRandomBytes(length int) ([]byte, error)

GenerateRandomBytes generates random bytes of specified length

func (*CryptoUtils) HashPassword

func (cu *CryptoUtils) HashPassword(password string) (string, error)

HashPassword hashes a password using bcrypt

func (*CryptoUtils) VerifyPassword

func (cu *CryptoUtils) VerifyPassword(password, hash string) bool

VerifyPassword verifies a password against its hash

type FileUtils

type FileUtils struct{}

FileUtils provides file utility functions

func NewFileUtils

func NewFileUtils() *FileUtils

NewFileUtils creates a new FileUtils instance

func (*FileUtils) FormatFileSize

func (fu *FileUtils) FormatFileSize(size int64) string

FormatFileSize formats a file size in bytes to human readable format

func (*FileUtils) GetFileExtension

func (fu *FileUtils) GetFileExtension(filename string) string

GetFileExtension gets the file extension from a filename

func (*FileUtils) GetFileNameWithoutExtension

func (fu *FileUtils) GetFileNameWithoutExtension(filename string) string

GetFileNameWithoutExtension gets the filename without extension

func (*FileUtils) IsValidDocumentExtension

func (fu *FileUtils) IsValidDocumentExtension(extension string) bool

IsValidDocumentExtension checks if a file extension is a valid document extension

func (*FileUtils) IsValidImageExtension

func (fu *FileUtils) IsValidImageExtension(extension string) bool

IsValidImageExtension checks if a file extension is a valid image extension

type LogUtils

type LogUtils struct {
	// contains filtered or unexported fields
}

LogUtils provides logging utility functions

func NewLogUtils

func NewLogUtils(logger *logrus.Logger) *LogUtils

NewLogUtils creates a new LogUtils instance

func (*LogUtils) LogDebug

func (lu *LogUtils) LogDebug(message string, fields logrus.Fields)

LogDebug logs a debug message with context

func (*LogUtils) LogError

func (lu *LogUtils) LogError(err error, message string, fields logrus.Fields)

LogError logs an error with context

func (*LogUtils) LogInfo

func (lu *LogUtils) LogInfo(message string, fields logrus.Fields)

LogInfo logs an info message with context

func (*LogUtils) LogWarning

func (lu *LogUtils) LogWarning(message string, fields logrus.Fields)

LogWarning logs a warning message with context

func (*LogUtils) LogWithDuration

func (lu *LogUtils) LogWithDuration(message string, duration time.Duration, fields logrus.Fields)

LogWithDuration logs a message with duration

func (*LogUtils) LogWithRequest

func (lu *LogUtils) LogWithRequest(message string, requestID, method, path string, fields logrus.Fields)

LogWithRequest logs a message with request context

func (*LogUtils) LogWithUser

func (lu *LogUtils) LogWithUser(message string, userID, tenantID string, fields logrus.Fields)

LogWithUser logs a message with user context

type StringUtils

type StringUtils struct{}

StringUtils provides string utility functions

func NewStringUtils

func NewStringUtils() *StringUtils

NewStringUtils creates a new StringUtils instance

func (*StringUtils) Capitalize

func (su *StringUtils) Capitalize(s string) string

Capitalize capitalizes the first letter of a string

func (*StringUtils) Contains

func (su *StringUtils) Contains(s, substr string) bool

Contains checks if a string contains a substring (case-insensitive)

func (*StringUtils) IsEmpty

func (su *StringUtils) IsEmpty(s string) bool

IsEmpty checks if a string is empty or contains only whitespace

func (*StringUtils) IsNotEmpty

func (su *StringUtils) IsNotEmpty(s string) bool

IsNotEmpty checks if a string is not empty

func (*StringUtils) RandomString

func (su *StringUtils) RandomString(length int) string

RandomString generates a random string of specified length

func (*StringUtils) Slugify

func (su *StringUtils) Slugify(s string) string

Slugify converts a string to a URL-friendly slug

func (*StringUtils) TitleCase

func (su *StringUtils) TitleCase(s string) string

TitleCase converts a string to title case

func (*StringUtils) Truncate

func (su *StringUtils) Truncate(s string, length int) string

Truncate truncates a string to the specified length

type TimeUtils

type TimeUtils struct{}

TimeUtils provides time utility functions

func NewTimeUtils

func NewTimeUtils() *TimeUtils

NewTimeUtils creates a new TimeUtils instance

func (*TimeUtils) AddDays

func (tu *TimeUtils) AddDays(t time.Time, days int) time.Time

AddDays adds days to a time

func (*TimeUtils) AddMonths

func (tu *TimeUtils) AddMonths(t time.Time, months int) time.Time

AddMonths adds months to a time

func (*TimeUtils) AddYears

func (tu *TimeUtils) AddYears(t time.Time, years int) time.Time

AddYears adds years to a time

func (*TimeUtils) FormatTime

func (tu *TimeUtils) FormatTime(t time.Time, layout string) string

FormatTime formats a time using the specified layout

func (*TimeUtils) GetEndOfDay

func (tu *TimeUtils) GetEndOfDay(t time.Time) time.Time

GetEndOfDay returns the end of the day for a given time

func (*TimeUtils) GetEndOfMonth

func (tu *TimeUtils) GetEndOfMonth(t time.Time) time.Time

GetEndOfMonth returns the end of the month for a given time

func (*TimeUtils) GetEndOfWeek

func (tu *TimeUtils) GetEndOfWeek(t time.Time) time.Time

GetEndOfWeek returns the end of the week for a given time

func (*TimeUtils) GetEndOfYear

func (tu *TimeUtils) GetEndOfYear(t time.Time) time.Time

GetEndOfYear returns the end of the year for a given time

func (*TimeUtils) GetStartOfDay

func (tu *TimeUtils) GetStartOfDay(t time.Time) time.Time

GetStartOfDay returns the start of the day for a given time

func (*TimeUtils) GetStartOfMonth

func (tu *TimeUtils) GetStartOfMonth(t time.Time) time.Time

GetStartOfMonth returns the start of the month for a given time

func (*TimeUtils) GetStartOfWeek

func (tu *TimeUtils) GetStartOfWeek(t time.Time) time.Time

GetStartOfWeek returns the start of the week for a given time

func (*TimeUtils) GetStartOfYear

func (tu *TimeUtils) GetStartOfYear(t time.Time) time.Time

GetStartOfYear returns the start of the year for a given time

func (*TimeUtils) IsThisMonth

func (tu *TimeUtils) IsThisMonth(t time.Time) bool

IsThisMonth checks if a time is this month

func (*TimeUtils) IsThisWeek

func (tu *TimeUtils) IsThisWeek(t time.Time) bool

IsThisWeek checks if a time is this week

func (*TimeUtils) IsThisYear

func (tu *TimeUtils) IsThisYear(t time.Time) bool

IsThisYear checks if a time is this year

func (*TimeUtils) IsToday

func (tu *TimeUtils) IsToday(t time.Time) bool

IsToday checks if a time is today

func (*TimeUtils) IsYesterday

func (tu *TimeUtils) IsYesterday(t time.Time) bool

IsYesterday checks if a time is yesterday

func (*TimeUtils) Now

func (tu *TimeUtils) Now() time.Time

Now returns the current time

func (*TimeUtils) NowUTC

func (tu *TimeUtils) NowUTC() time.Time

NowUTC returns the current time in UTC

func (*TimeUtils) ParseTime

func (tu *TimeUtils) ParseTime(timeStr, layout string) (time.Time, error)

ParseTime parses a time string using the specified layout

type UUIDUtils

type UUIDUtils struct{}

UUIDUtils provides UUID utility functions

func NewUUIDUtils

func NewUUIDUtils() *UUIDUtils

NewUUIDUtils creates a new UUIDUtils instance

func (*UUIDUtils) Generate

func (uu *UUIDUtils) Generate() uuid.UUID

Generate generates a new UUID

func (*UUIDUtils) GenerateString

func (uu *UUIDUtils) GenerateString() string

GenerateString generates a new UUID as a string

func (*UUIDUtils) IsValid

func (uu *UUIDUtils) IsValid(uuidStr string) bool

IsValid checks if a string is a valid UUID

func (*UUIDUtils) Parse

func (uu *UUIDUtils) Parse(uuidStr string) (uuid.UUID, error)

Parse parses a UUID string

type ValidationUtils

type ValidationUtils struct{}

ValidationUtils provides validation utility functions

func NewValidationUtils

func NewValidationUtils() *ValidationUtils

NewValidationUtils creates a new ValidationUtils instance

func (*ValidationUtils) IsValidEmail

func (vu *ValidationUtils) IsValidEmail(email string) bool

IsValidEmail validates an email address

func (*ValidationUtils) IsValidPassword

func (vu *ValidationUtils) IsValidPassword(password string) bool

IsValidPassword validates a password (minimum 8 characters, at least one letter and one number)

func (*ValidationUtils) IsValidPhone

func (vu *ValidationUtils) IsValidPhone(phone string) bool

IsValidPhone validates a phone number

func (*ValidationUtils) IsValidURL

func (vu *ValidationUtils) IsValidURL(url string) bool

IsValidURL validates a URL

func (*ValidationUtils) IsValidUUID

func (vu *ValidationUtils) IsValidUUID(uuidStr string) bool

IsValidUUID validates a UUID

Jump to

Keyboard shortcuts

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