Documentation
¶
Index ¶
- Variables
- func Base64URLDecode(s string) ([]byte, error)
- func Base64URLEncode(data []byte) string
- func ConstantTimeCompare(a, b []byte) bool
- func ContainsString(items []string, target string) bool
- func CorrelationID(ctx context.Context) string
- func EnsureCorrelationID(ctx context.Context) (context.Context, string)
- func EnsureRequestID(ctx context.Context) (context.Context, string)
- func GenerateHash(input string) string
- func GenerateUUID() uuid.UUID
- func GenerateUUIDString() string
- func GetEnvBool(key string, def bool) bool
- func GetEnvDuration(key string, def time.Duration) time.Duration
- func GetEnvInt(key string, def int) int
- func GetEnvString(key, def string) string
- func GzipCompress(data []byte) ([]byte, error)
- func GzipDecompress(data []byte) ([]byte, error)
- func HMACSHA256(message, secret []byte) []byte
- func HMACSHA256Hex(message, secret string) string
- func HashPassword(password string) (string, error)
- func IsEmpty(s string) bool
- func IsNotEmpty(s string) bool
- func IsValidEmail(email string) bool
- func IsValidPassword(password string) bool
- func IsValidPhone(phone string) bool
- func IsValidURL(url string) bool
- func IsValidUUID(uuidStr string) bool
- func JSONDecode(data []byte, v any) error
- func JSONEncode(v any) ([]byte, error)
- func JSONPretty(v any) (string, error)
- func Now() time.Time
- func NowUTC() time.Time
- func RandomHex(n int) (string, error)
- func RequestID(ctx context.Context) string
- func Retry(ctx context.Context, attempts int, initialBackoff, maxBackoff time.Duration, ...) error
- func RetryWithResult[T any](ctx context.Context, attempts int, initialBackoff, maxBackoff time.Duration, ...) (T, error)
- func UniqueStrings(items []string) []string
- func VerifyPassword(password, hash string) bool
- func WithCorrelationID(ctx context.Context, correlationID string) context.Context
- func WithRequestID(ctx context.Context, requestID string) context.Context
- type ContextUtils
- func (cu *ContextUtils) CorrelationID(ctx context.Context) string
- func (cu *ContextUtils) EnsureCorrelationID(ctx context.Context) (context.Context, string)
- func (cu *ContextUtils) EnsureRequestID(ctx context.Context) (context.Context, string)
- func (cu *ContextUtils) RequestID(ctx context.Context) string
- func (cu *ContextUtils) WithCorrelationID(ctx context.Context, correlationID string) context.Context
- func (cu *ContextUtils) WithRequestID(ctx context.Context, requestID string) context.Context
- type CryptoUtils
- func (cu *CryptoUtils) ConstantTimeCompare(a, b []byte) bool
- func (cu *CryptoUtils) GenerateHash(input string) string
- func (cu *CryptoUtils) GenerateRandomBytes(length int) ([]byte, error)
- func (cu *CryptoUtils) HMACSHA256(message, secret []byte) []byte
- func (cu *CryptoUtils) HMACSHA256Hex(message, secret string) string
- func (cu *CryptoUtils) HashPassword(password string) (string, error)
- func (cu *CryptoUtils) RandomHex(n int) (string, error)
- func (cu *CryptoUtils) VerifyPassword(password, hash string) bool
- type DataUtils
- func (du *DataUtils) Base64URLDecode(s string) ([]byte, error)
- func (du *DataUtils) Base64URLEncode(data []byte) string
- func (du *DataUtils) GzipCompress(data []byte) ([]byte, error)
- func (du *DataUtils) GzipDecompress(data []byte) ([]byte, error)
- func (du *DataUtils) JSONDecode(data []byte, v any) error
- func (du *DataUtils) JSONEncode(v any) ([]byte, error)
- func (du *DataUtils) JSONPretty(v any) (string, error)
- type EnvUtils
- type FileUtils
- func (fu *FileUtils) FormatFileSize(size int64) string
- func (fu *FileUtils) GetFileExtension(filename string) string
- func (fu *FileUtils) GetFileNameWithoutExtension(filename string) string
- func (fu *FileUtils) IsValidDocumentExtension(extension string) bool
- func (fu *FileUtils) IsValidImageExtension(extension string) bool
- type LogUtils
- func (lu *LogUtils) LogDebug(message string, fields logrus.Fields)
- func (lu *LogUtils) LogError(err error, message string, fields logrus.Fields)
- func (lu *LogUtils) LogInfo(message string, fields logrus.Fields)
- func (lu *LogUtils) LogWarning(message string, fields logrus.Fields)
- func (lu *LogUtils) LogWithDuration(message string, duration time.Duration, fields logrus.Fields)
- func (lu *LogUtils) LogWithRequest(message string, requestID, method, path string, fields logrus.Fields)
- func (lu *LogUtils) LogWithUser(message string, userID, tenantID string, fields logrus.Fields)
- type RetryUtils
- type SliceUtils
- type StringUtils
- func (su *StringUtils) Capitalize(s string) string
- func (su *StringUtils) Contains(s, substr string) bool
- func (su *StringUtils) IsEmpty(s string) bool
- func (su *StringUtils) IsNotEmpty(s string) bool
- func (su *StringUtils) RandomString(length int) string
- func (su *StringUtils) Slugify(s string) string
- func (su *StringUtils) TitleCase(s string) string
- func (su *StringUtils) Truncate(s string, length int) string
- type TimeUtils
- func (tu *TimeUtils) AddDays(t time.Time, days int) time.Time
- func (tu *TimeUtils) AddMonths(t time.Time, months int) time.Time
- func (tu *TimeUtils) AddYears(t time.Time, years int) time.Time
- func (tu *TimeUtils) FormatTime(t time.Time, layout string) string
- func (tu *TimeUtils) GetEndOfDay(t time.Time) time.Time
- func (tu *TimeUtils) GetEndOfMonth(t time.Time) time.Time
- func (tu *TimeUtils) GetEndOfWeek(t time.Time) time.Time
- func (tu *TimeUtils) GetEndOfYear(t time.Time) time.Time
- func (tu *TimeUtils) GetStartOfDay(t time.Time) time.Time
- func (tu *TimeUtils) GetStartOfMonth(t time.Time) time.Time
- func (tu *TimeUtils) GetStartOfWeek(t time.Time) time.Time
- func (tu *TimeUtils) GetStartOfYear(t time.Time) time.Time
- func (tu *TimeUtils) IsThisMonth(t time.Time) bool
- func (tu *TimeUtils) IsThisWeek(t time.Time) bool
- func (tu *TimeUtils) IsThisYear(t time.Time) bool
- func (tu *TimeUtils) IsToday(t time.Time) bool
- func (tu *TimeUtils) IsYesterday(t time.Time) bool
- func (tu *TimeUtils) Now() time.Time
- func (tu *TimeUtils) NowUTC() time.Time
- func (tu *TimeUtils) ParseTime(timeStr, layout string) (time.Time, error)
- type UUIDUtils
- type ValidationUtils
- func (vu *ValidationUtils) IsValidEmail(email string) bool
- func (vu *ValidationUtils) IsValidPassword(password string) bool
- func (vu *ValidationUtils) IsValidPhone(phone string) bool
- func (vu *ValidationUtils) IsValidURL(url string) bool
- func (vu *ValidationUtils) IsValidUUID(uuidStr string) bool
- func (vu *ValidationUtils) ValidatePasswordWithDetails(password string) (bool, []string)
Constants ¶
This section is empty.
Variables ¶
var ( StringUtilsInstance = NewStringUtils() ValidationUtilsInstance = NewValidationUtils() CryptoUtilsInstance = NewCryptoUtils() TimeUtilsInstance = NewTimeUtils() UUIDUtilsInstance = NewUUIDUtils() FileUtilsInstance = NewFileUtils() RetryUtilsInstance = NewRetryUtils() ContextUtilsInstance = NewContextUtils() EnvUtilsInstance = NewEnvUtils() DataUtilsInstance = NewDataUtils() SliceUtilsInstance = NewSliceUtils() )
Global utility instances for backward compatibility
Functions ¶
func Base64URLDecode ¶ added in v1.1.3
func Base64URLEncode ¶ added in v1.1.3
func ConstantTimeCompare ¶ added in v1.1.3
func ContainsString ¶ added in v1.1.3
Convenience wrappers
func CorrelationID ¶ added in v1.1.3
func EnsureCorrelationID ¶ added in v1.1.3
func EnsureRequestID ¶ added in v1.1.3
func GenerateHash ¶
func GenerateUUID ¶
func GenerateUUIDString ¶
func GenerateUUIDString() string
func GetEnvBool ¶ added in v1.1.3
func GetEnvDuration ¶ added in v1.1.3
func GzipCompress ¶ added in v1.1.3
func GzipDecompress ¶ added in v1.1.3
func HMACSHA256 ¶ added in v1.1.3
Convenience wrappers
func HMACSHA256Hex ¶ added in v1.1.3
func HashPassword ¶
func IsNotEmpty ¶
func IsValidEmail ¶
func IsValidPassword ¶
func IsValidPhone ¶
func IsValidURL ¶
func IsValidUUID ¶
func JSONDecode ¶ added in v1.1.3
func JSONPretty ¶ added in v1.1.3
func Retry ¶ added in v1.1.3
func Retry(ctx context.Context, attempts int, initialBackoff, maxBackoff time.Duration, fn func() error) error
Convenience wrappers
func RetryWithResult ¶ added in v1.1.3
func RetryWithResult[T any](ctx context.Context, attempts int, initialBackoff, maxBackoff time.Duration, fn func() (T, error)) (T, error)
RetryWithResult executes fn with retries and returns its result
func UniqueStrings ¶ added in v1.1.3
func VerifyPassword ¶
func WithCorrelationID ¶ added in v1.1.3
Types ¶
type ContextUtils ¶ added in v1.1.3
type ContextUtils struct{}
ContextUtils provides helpers for common IDs in context
func NewContextUtils ¶ added in v1.1.3
func NewContextUtils() *ContextUtils
NewContextUtils creates a new ContextUtils instance
func (*ContextUtils) CorrelationID ¶ added in v1.1.3
func (cu *ContextUtils) CorrelationID(ctx context.Context) string
CorrelationID gets a correlation ID from context
func (*ContextUtils) EnsureCorrelationID ¶ added in v1.1.3
EnsureCorrelationID returns a context with correlation ID set and the ID value
func (*ContextUtils) EnsureRequestID ¶ added in v1.1.3
EnsureRequestID returns a context with request ID set and the ID value
func (*ContextUtils) RequestID ¶ added in v1.1.3
func (cu *ContextUtils) RequestID(ctx context.Context) string
RequestID gets a request ID from context, empty if missing
func (*ContextUtils) WithCorrelationID ¶ added in v1.1.3
func (cu *ContextUtils) WithCorrelationID(ctx context.Context, correlationID string) context.Context
WithCorrelationID attaches a correlation ID to context
func (*ContextUtils) WithRequestID ¶ added in v1.1.3
WithRequestID attaches a request ID to context
type CryptoUtils ¶
type CryptoUtils struct{}
CryptoUtils provides cryptographic utility functions
func NewCryptoUtils ¶
func NewCryptoUtils() *CryptoUtils
NewCryptoUtils creates a new CryptoUtils instance
func (*CryptoUtils) ConstantTimeCompare ¶ added in v1.1.3
func (cu *CryptoUtils) ConstantTimeCompare(a, b []byte) bool
ConstantTimeCompare compares two byte slices in constant time
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) HMACSHA256 ¶ added in v1.1.3
func (cu *CryptoUtils) HMACSHA256(message, secret []byte) []byte
HMACSHA256 returns HMAC-SHA256 bytes of message with secret key
func (*CryptoUtils) HMACSHA256Hex ¶ added in v1.1.3
func (cu *CryptoUtils) HMACSHA256Hex(message, secret string) string
HMACSHA256Hex returns lowercase hex HMAC of message with secret string
func (*CryptoUtils) HashPassword ¶
func (cu *CryptoUtils) HashPassword(password string) (string, error)
HashPassword hashes a password using bcrypt
func (*CryptoUtils) RandomHex ¶ added in v1.1.3
func (cu *CryptoUtils) RandomHex(n int) (string, error)
RandomHex returns hex string of n random bytes
func (*CryptoUtils) VerifyPassword ¶
func (cu *CryptoUtils) VerifyPassword(password, hash string) bool
VerifyPassword verifies a password against its hash
type DataUtils ¶ added in v1.1.3
type DataUtils struct{}
DataUtils provides encoding/decoding helpers
func NewDataUtils ¶ added in v1.1.3
func NewDataUtils() *DataUtils
NewDataUtils creates a new DataUtils instance
func (*DataUtils) Base64URLDecode ¶ added in v1.1.3
func (*DataUtils) Base64URLEncode ¶ added in v1.1.3
func (*DataUtils) GzipCompress ¶ added in v1.1.3
func (*DataUtils) GzipDecompress ¶ added in v1.1.3
func (*DataUtils) JSONDecode ¶ added in v1.1.3
func (*DataUtils) JSONEncode ¶ added in v1.1.3
type EnvUtils ¶ added in v1.1.3
type EnvUtils struct{}
EnvUtils provides environment variable helpers
func NewEnvUtils ¶ added in v1.1.3
func NewEnvUtils() *EnvUtils
NewEnvUtils creates a new EnvUtils instance
func (*EnvUtils) GetDuration ¶ added in v1.1.3
type FileUtils ¶
type FileUtils struct{}
FileUtils provides file utility functions
func (*FileUtils) FormatFileSize ¶
FormatFileSize formats a file size in bytes to human readable format
func (*FileUtils) GetFileExtension ¶
GetFileExtension gets the file extension from a filename
func (*FileUtils) GetFileNameWithoutExtension ¶
GetFileNameWithoutExtension gets the filename without extension
func (*FileUtils) IsValidDocumentExtension ¶
IsValidDocumentExtension checks if a file extension is a valid document extension
func (*FileUtils) IsValidImageExtension ¶
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 ¶
NewLogUtils creates a new LogUtils instance
func (*LogUtils) LogWarning ¶
LogWarning logs a warning message with context
func (*LogUtils) LogWithDuration ¶
LogWithDuration logs a message with duration
type RetryUtils ¶ added in v1.1.3
type RetryUtils struct{}
RetryUtils provides retry with backoff helpers
func NewRetryUtils ¶ added in v1.1.3
func NewRetryUtils() *RetryUtils
NewRetryUtils creates a new RetryUtils instance
type SliceUtils ¶ added in v1.1.3
type SliceUtils struct{}
SliceUtils provides slice helpers
func NewSliceUtils ¶ added in v1.1.3
func NewSliceUtils() *SliceUtils
NewSliceUtils creates a new SliceUtils instance
func (*SliceUtils) ContainsString ¶ added in v1.1.3
func (su2 *SliceUtils) ContainsString(items []string, target string) bool
func (*SliceUtils) UniqueStrings ¶ added in v1.1.3
func (su2 *SliceUtils) UniqueStrings(items []string) []string
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
type TimeUtils ¶
type TimeUtils struct{}
TimeUtils provides time utility functions
func (*TimeUtils) FormatTime ¶
FormatTime formats a time using the specified layout
func (*TimeUtils) GetEndOfDay ¶
GetEndOfDay returns the end of the day for a given time
func (*TimeUtils) GetEndOfMonth ¶
GetEndOfMonth returns the end of the month for a given time
func (*TimeUtils) GetEndOfWeek ¶
GetEndOfWeek returns the end of the week for a given time
func (*TimeUtils) GetEndOfYear ¶
GetEndOfYear returns the end of the year for a given time
func (*TimeUtils) GetStartOfDay ¶
GetStartOfDay returns the start of the day for a given time
func (*TimeUtils) GetStartOfMonth ¶
GetStartOfMonth returns the start of the month for a given time
func (*TimeUtils) GetStartOfWeek ¶
GetStartOfWeek returns the start of the week for a given time
func (*TimeUtils) GetStartOfYear ¶
GetStartOfYear returns the start of the year for a given time
func (*TimeUtils) IsThisMonth ¶
IsThisMonth checks if a time is this month
func (*TimeUtils) IsThisWeek ¶
IsThisWeek checks if a time is this week
func (*TimeUtils) IsThisYear ¶
IsThisYear checks if a time is this year
func (*TimeUtils) IsYesterday ¶
IsYesterday checks if a time is yesterday
type UUIDUtils ¶
type UUIDUtils struct{}
UUIDUtils provides UUID utility functions
func (*UUIDUtils) GenerateString ¶
GenerateString generates a new UUID as a 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 with strong requirements
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
func (*ValidationUtils) ValidatePasswordWithDetails ¶ added in v1.1.1
func (vu *ValidationUtils) ValidatePasswordWithDetails(password string) (bool, []string)
ValidatePasswordWithDetails validates a password and returns detailed error messages