utils

package
v1.1.2 Latest Latest
Warning

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

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

README

Utils Library

The Utils library provides a comprehensive collection of utility functions for common operations including string manipulation, validation, cryptography, time handling, UUID generation, logging, and file operations. It offers a clean, consistent API with both instance-based and global convenience functions for maximum flexibility and ease of use.

Features

  • String Utilities: String manipulation, formatting, and validation
  • Validation Utilities: Email, phone, URL, UUID, and password validation
  • Cryptographic Utilities: Password hashing, verification, and hash generation
  • Time Utilities: Time manipulation, formatting, and date calculations
  • UUID Utilities: UUID generation, parsing, and validation
  • Logging Utilities: Structured logging with context
  • File Utilities: File extension handling and size formatting
  • Global Functions: Convenience functions for quick access
  • Type Safety: Strong typing with comprehensive error handling
  • Performance: Optimized implementations for common operations

Installation

go get github.com/anasamu/go-micro-libs/utils

Quick Start

package main

import (
    "fmt"
    "log"
    "time"

    "github.com/anasamu/go-micro-libs/utils"
    "github.com/sirupsen/logrus"
)

func main() {
    // String utilities
    stringUtils := utils.NewStringUtils()
    
    // Check if string is empty
    if stringUtils.IsEmpty("") {
        fmt.Println("String is empty")
    }
    
    // Capitalize string
    capitalized := stringUtils.Capitalize("hello world")
    fmt.Printf("Capitalized: %s\n", capitalized) // "Hello world"
    
    // Create URL-friendly slug
    slug := stringUtils.Slugify("Hello World! This is a test.")
    fmt.Printf("Slug: %s\n", slug) // "hello-world-this-is-a-test"
    
    // Generate random string
    randomStr := stringUtils.RandomString(10)
    fmt.Printf("Random string: %s\n", randomStr)
    
    // Validation utilities
    validationUtils := utils.NewValidationUtils()
    
    // Validate email
    if validationUtils.IsValidEmail("user@example.com") {
        fmt.Println("Valid email")
    }
    
    // Validate password with details
    isValid, errors := validationUtils.ValidatePasswordWithDetails("MySecure123!")
    if !isValid {
        fmt.Printf("Password validation errors: %v\n", errors)
    } else {
        fmt.Println("Password is valid")
    }
    
    // Cryptographic utilities
    cryptoUtils := utils.NewCryptoUtils()
    
    // Hash password
    hashedPassword, err := cryptoUtils.HashPassword("MySecure123!")
    if err != nil {
        log.Fatalf("Failed to hash password: %v", err)
    }
    fmt.Printf("Hashed password: %s\n", hashedPassword)
    
    // Verify password
    isValidPassword := cryptoUtils.VerifyPassword("MySecure123!", hashedPassword)
    fmt.Printf("Password verification: %v\n", isValidPassword)
    
    // Generate hash
    hash := cryptoUtils.GenerateHash("Hello World")
    fmt.Printf("SHA256 hash: %s\n", hash)
    
    // Time utilities
    timeUtils := utils.NewTimeUtils()
    
    // Get current time
    now := timeUtils.Now()
    fmt.Printf("Current time: %s\n", now.Format(time.RFC3339))
    
    // Check if time is today
    if timeUtils.IsToday(now) {
        fmt.Println("Time is today")
    }
    
    // Get start and end of day
    startOfDay := timeUtils.GetStartOfDay(now)
    endOfDay := timeUtils.GetEndOfDay(now)
    fmt.Printf("Start of day: %s\n", startOfDay.Format(time.RFC3339))
    fmt.Printf("End of day: %s\n", endOfDay.Format(time.RFC3339))
    
    // UUID utilities
    uuidUtils := utils.NewUUIDUtils()
    
    // Generate UUID
    newUUID := uuidUtils.Generate()
    fmt.Printf("Generated UUID: %s\n", newUUID.String())
    
    // Validate UUID
    if uuidUtils.IsValid(newUUID.String()) {
        fmt.Println("UUID is valid")
    }
    
    // File utilities
    fileUtils := utils.NewFileUtils()
    
    // Get file extension
    extension := fileUtils.GetFileExtension("document.pdf")
    fmt.Printf("File extension: %s\n", extension)
    
    // Check if extension is valid image
    if fileUtils.IsValidImageExtension("jpg") {
        fmt.Println("Valid image extension")
    }
    
    // Format file size
    formattedSize := fileUtils.FormatFileSize(1024 * 1024) // 1MB
    fmt.Printf("Formatted size: %s\n", formattedSize)
    
    // Logging utilities
    logger := logrus.New()
    logUtils := utils.NewLogUtils(logger)
    
    // Log with context
    logUtils.LogInfo("Application started", logrus.Fields{
        "version": "1.0.0",
        "port":    8080,
    })
    
    // Log with user context
    logUtils.LogWithUser("User action performed", "user-123", "tenant-1", logrus.Fields{
        "action": "login",
        "ip":     "192.168.1.1",
    })
    
    // Global convenience functions
    fmt.Printf("Is empty: %v\n", utils.IsEmpty(""))
    fmt.Printf("Is valid email: %v\n", utils.IsValidEmail("test@example.com"))
    fmt.Printf("Current time: %s\n", utils.Now().Format(time.RFC3339))
    fmt.Printf("Generated UUID: %s\n", utils.GenerateUUIDString())
}

API Reference

String Utilities
Instance Methods
  • IsEmpty(s string) bool - Check if string is empty or whitespace only
  • IsNotEmpty(s string) bool - Check if string is not empty
  • Truncate(s string, length int) string - Truncate string to specified length
  • Capitalize(s string) string - Capitalize first letter
  • TitleCase(s string) string - Convert to title case
  • Slugify(s string) string - Convert to URL-friendly slug
  • Contains(s, substr string) bool - Case-insensitive substring check
  • RandomString(length int) string - Generate random string
Global Functions
  • IsEmpty(s string) bool
  • IsNotEmpty(s string) bool
Validation Utilities
Instance Methods
  • IsValidEmail(email string) bool - Validate email address
  • IsValidPhone(phone string) bool - Validate phone number
  • IsValidURL(url string) bool - Validate URL
  • IsValidUUID(uuidStr string) bool - Validate UUID
  • IsValidPassword(password string) bool - Validate password strength
  • ValidatePasswordWithDetails(password string) (bool, []string) - Detailed password validation
Global Functions
  • IsValidEmail(email string) bool
  • IsValidPhone(phone string) bool
  • IsValidURL(url string) bool
  • IsValidUUID(uuidStr string) bool
  • IsValidPassword(password string) bool
Cryptographic Utilities
Instance Methods
  • HashPassword(password string) (string, error) - Hash password with bcrypt
  • VerifyPassword(password, hash string) bool - Verify password against hash
  • GenerateHash(input string) string - Generate SHA256 hash
  • GenerateRandomBytes(length int) ([]byte, error) - Generate random bytes
Global Functions
  • HashPassword(password string) (string, error)
  • VerifyPassword(password, hash string) bool
  • GenerateHash(input string) string
Time Utilities
Instance Methods
  • Now() time.Time - Get current time
  • NowUTC() time.Time - Get current UTC time
  • FormatTime(t time.Time, layout string) string - Format time
  • ParseTime(timeStr, layout string) (time.Time, error) - Parse time string
  • IsToday(t time.Time) bool - Check if time is today
  • IsYesterday(t time.Time) bool - Check if time is yesterday
  • IsThisWeek(t time.Time) bool - Check if time is this week
  • IsThisMonth(t time.Time) bool - Check if time is this month
  • IsThisYear(t time.Time) bool - Check if time is this year
  • AddDays(t time.Time, days int) time.Time - Add days to time
  • AddMonths(t time.Time, months int) time.Time - Add months to time
  • AddYears(t time.Time, years int) time.Time - Add years to time
  • GetStartOfDay(t time.Time) time.Time - Get start of day
  • GetEndOfDay(t time.Time) time.Time - Get end of day
  • GetStartOfWeek(t time.Time) time.Time - Get start of week
  • GetEndOfWeek(t time.Time) time.Time - Get end of week
  • GetStartOfMonth(t time.Time) time.Time - Get start of month
  • GetEndOfMonth(t time.Time) time.Time - Get end of month
  • GetStartOfYear(t time.Time) time.Time - Get start of year
  • GetEndOfYear(t time.Time) time.Time - Get end of year
Global Functions
  • Now() time.Time
  • NowUTC() time.Time
UUID Utilities
Instance Methods
  • Generate() uuid.UUID - Generate new UUID
  • GenerateString() string - Generate UUID as string
  • Parse(uuidStr string) (uuid.UUID, error) - Parse UUID string
  • IsValid(uuidStr string) bool - Validate UUID string
Global Functions
  • GenerateUUID() uuid.UUID
  • GenerateUUIDString() string
Logging Utilities
Instance Methods
  • LogError(err error, message string, fields logrus.Fields) - Log error with context
  • LogInfo(message string, fields logrus.Fields) - Log info message
  • LogWarning(message string, fields logrus.Fields) - Log warning message
  • LogDebug(message string, fields logrus.Fields) - Log debug message
  • LogWithDuration(message string, duration time.Duration, fields logrus.Fields) - Log with duration
  • LogWithUser(message string, userID, tenantID string, fields logrus.Fields) - Log with user context
  • LogWithRequest(message string, requestID, method, path string, fields logrus.Fields) - Log with request context
File Utilities
Instance Methods
  • GetFileExtension(filename string) string - Get file extension
  • GetFileNameWithoutExtension(filename string) string - Get filename without extension
  • IsValidImageExtension(extension string) bool - Check if valid image extension
  • IsValidDocumentExtension(extension string) bool - Check if valid document extension
  • FormatFileSize(size int64) string - Format file size in human readable format

Usage Examples

String Manipulation
stringUtils := utils.NewStringUtils()

// Basic string operations
fmt.Println(stringUtils.IsEmpty(""))           // true
fmt.Println(stringUtils.IsNotEmpty("hello"))   // true
fmt.Println(stringUtils.Capitalize("hello"))   // "Hello"
fmt.Println(stringUtils.TitleCase("hello world")) // "Hello World"

// URL-friendly slug generation
slug := stringUtils.Slugify("Hello World! This is a test.")
fmt.Println(slug) // "hello-world-this-is-a-test"

// String truncation
truncated := stringUtils.Truncate("This is a very long string", 10)
fmt.Println(truncated) // "This is a ..."

// Random string generation
random := stringUtils.RandomString(8)
fmt.Println(random) // Random 8-character string
Validation
validationUtils := utils.NewValidationUtils()

// Email validation
fmt.Println(validationUtils.IsValidEmail("user@example.com")) // true
fmt.Println(validationUtils.IsValidEmail("invalid-email"))    // false

// Phone validation
fmt.Println(validationUtils.IsValidPhone("+1234567890"))      // true
fmt.Println(validationUtils.IsValidPhone("invalid-phone"))    // false

// URL validation
fmt.Println(validationUtils.IsValidURL("https://example.com")) // true
fmt.Println(validationUtils.IsValidURL("invalid-url"))         // false

// Password validation with details
isValid, errors := validationUtils.ValidatePasswordWithDetails("weak")
if !isValid {
    for _, err := range errors {
        fmt.Println(err)
    }
}
Password Security
cryptoUtils := utils.NewCryptoUtils()

// Hash password
password := "MySecure123!"
hashedPassword, err := cryptoUtils.HashPassword(password)
if err != nil {
    log.Fatal(err)
}

// Verify password
isValid := cryptoUtils.VerifyPassword(password, hashedPassword)
fmt.Printf("Password verification: %v\n", isValid)

// Generate hash for other purposes
hash := cryptoUtils.GenerateHash("Hello World")
fmt.Printf("SHA256 hash: %s\n", hash)
Time Operations
timeUtils := utils.NewTimeUtils()

// Current time
now := timeUtils.Now()
fmt.Printf("Current time: %s\n", now.Format(time.RFC3339))

// Date calculations
startOfDay := timeUtils.GetStartOfDay(now)
endOfDay := timeUtils.GetEndOfDay(now)
fmt.Printf("Start of day: %s\n", startOfDay.Format(time.RFC3339))
fmt.Printf("End of day: %s\n", endOfDay.Format(time.RFC3339))

// Week calculations
startOfWeek := timeUtils.GetStartOfWeek(now)
endOfWeek := timeUtils.GetEndOfWeek(now)
fmt.Printf("Start of week: %s\n", startOfWeek.Format(time.RFC3339))
fmt.Printf("End of week: %s\n", endOfWeek.Format(time.RFC3339))

// Month calculations
startOfMonth := timeUtils.GetStartOfMonth(now)
endOfMonth := timeUtils.GetEndOfMonth(now)
fmt.Printf("Start of month: %s\n", startOfMonth.Format(time.RFC3339))
fmt.Printf("End of month: %s\n", endOfMonth.Format(time.RFC3339))

// Time checks
fmt.Printf("Is today: %v\n", timeUtils.IsToday(now))
fmt.Printf("Is this week: %v\n", timeUtils.IsThisWeek(now))
fmt.Printf("Is this month: %v\n", timeUtils.IsThisMonth(now))
UUID Generation
uuidUtils := utils.NewUUIDUtils()

// Generate UUID
newUUID := uuidUtils.Generate()
fmt.Printf("Generated UUID: %s\n", newUUID.String())

// Generate UUID as string
uuidString := uuidUtils.GenerateString()
fmt.Printf("UUID string: %s\n", uuidString)

// Validate UUID
isValid := uuidUtils.IsValid(uuidString)
fmt.Printf("UUID is valid: %v\n", isValid)

// Parse UUID
parsedUUID, err := uuidUtils.Parse(uuidString)
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Parsed UUID: %s\n", parsedUUID.String())
Structured Logging
logger := logrus.New()
logUtils := utils.NewLogUtils(logger)

// Basic logging
logUtils.LogInfo("Application started", logrus.Fields{
    "version": "1.0.0",
    "port":    8080,
})

// Error logging
err := fmt.Errorf("database connection failed")
logUtils.LogError(err, "Failed to connect to database", logrus.Fields{
    "host": "localhost",
    "port": 5432,
})

// User context logging
logUtils.LogWithUser("User logged in", "user-123", "tenant-1", logrus.Fields{
    "ip_address": "192.168.1.1",
    "user_agent": "Mozilla/5.0",
})

// Request context logging
logUtils.LogWithRequest("API request processed", "req-456", "GET", "/api/users", logrus.Fields{
    "status_code": 200,
    "duration":    "150ms",
})

// Duration logging
start := time.Now()
// ... perform operation ...
duration := time.Since(start)
logUtils.LogWithDuration("Operation completed", duration, logrus.Fields{
    "operation": "data_processing",
})
File Operations
fileUtils := utils.NewFileUtils()

// File extension operations
filename := "document.pdf"
extension := fileUtils.GetFileExtension(filename)
fmt.Printf("File extension: %s\n", extension) // "pdf"

nameWithoutExt := fileUtils.GetFileNameWithoutExtension(filename)
fmt.Printf("Name without extension: %s\n", nameWithoutExt) // "document"

// File type validation
fmt.Printf("Is valid image: %v\n", fileUtils.IsValidImageExtension("jpg"))     // true
fmt.Printf("Is valid image: %v\n", fileUtils.IsValidImageExtension("txt"))     // false
fmt.Printf("Is valid document: %v\n", fileUtils.IsValidDocumentExtension("pdf")) // true
fmt.Printf("Is valid document: %v\n", fileUtils.IsValidDocumentExtension("jpg")) // false

// File size formatting
fmt.Printf("Formatted size: %s\n", fileUtils.FormatFileSize(1024))           // "1.0 KB"
fmt.Printf("Formatted size: %s\n", fileUtils.FormatFileSize(1024*1024))      // "1.0 MB"
fmt.Printf("Formatted size: %s\n", fileUtils.FormatFileSize(1024*1024*1024)) // "1.0 GB"

Best Practices

Performance
  1. Reuse Instances: Create utility instances once and reuse them
  2. Global Functions: Use global functions for simple operations
  3. Error Handling: Always handle errors appropriately
  4. Validation: Validate inputs before processing
Security
  1. Password Hashing: Always use the provided password hashing functions
  2. Input Validation: Validate all user inputs
  3. Random Generation: Use the provided random generation functions
  4. Logging: Be careful not to log sensitive information
Code Organization
  1. Consistent Usage: Use either instance methods or global functions consistently
  2. Error Handling: Implement proper error handling
  3. Logging: Use structured logging for better debugging
  4. Documentation: Document custom utility functions

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

License

This library is licensed under the MIT License. See the LICENSE file for details.

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 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

Jump to

Keyboard shortcuts

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