Documentation
¶
Index ¶
- func AddToContext(ctx context.Context, key models.ContextKey, value interface{}) context.Context
- func CalculateOffset(page, pageSize int) int
- func Coalesce(values ...string) string
- func ContainsInt(slice []int, item int) bool
- func ContainsString(slice []string, item string) bool
- func ConvertToUUID(dataString string) uuid.UUID
- func CreateError(message string) error
- func CreateErrorf(format string, args ...interface{}) error
- func DefaultIfEmpty(value string, defaultValue string) string
- func DirectoryExists(dirPath string) bool
- func EnsureDirectory(dirPath string) error
- func FileExists(filePath string) bool
- func FormatTimestamp(t time.Time, layout string) string
- func GenerateOTP() (int, error)
- func GenerateRandomString(length int) (string, error)
- func GenerateSecureOTPString(length int) (string, error)
- func GenerateUUID() uuid.UUID
- func GenerateUUIDString() string
- func GetClientIP(request *http.Request) string
- func GetContextData(request *http.Request, key models.ContextKey) uuid.UUID
- func GetCurrentTimestamp() time.Time
- func GetCurrentTimestampString() string
- func GetENVBoolValue(key string, defaultValue bool) bool
- func GetENVIntValue(key string, defaultValue int) int
- func GetENVValue(key string) string
- func GetENVValueWithDefault(key string, defaultValue string) string
- func GetFileSize(filePath string) (int64, error)
- func GetFileType(filename string) string
- func GetFormFile(request *http.Request, fieldName string) (multipart.File, *multipart.FileHeader, error)
- func GetFromContext(ctx context.Context, key models.ContextKey) (interface{}, bool)
- func GetIntContextData(request *http.Request, key models.ContextKey) int
- func GetIntFromContext(ctx context.Context, key models.ContextKey) int
- func GetPaginationParams(request *http.Request) (page int, pageSize int)
- func GetQueryBool(request *http.Request, key string, defaultValue bool) bool
- func GetQueryID(request *http.Request) uuid.UUID
- func GetQueryInt(request *http.Request, key string, defaultValue int) int
- func GetQueryParam(request *http.Request, key string, defaultValue string) string
- func GetQueryUUID(request *http.Request) uuid.UUID
- func GetSearchKeyword(request *http.Request) string
- func GetStringContextData(request *http.Request, key models.ContextKey) string
- func GetStringFromContext(ctx context.Context, key models.ContextKey) string
- func GetUUIDContextData(request *http.Request, key models.ContextKey) uuid.UUID
- func GetUserAgent(request *http.Request) string
- func IsDocumentFile(filename string) bool
- func IsImageFile(filename string) bool
- func IsValidUUID(providedID string) bool
- func IsVideoFile(filename string) bool
- func IsZeroUUID(ID uuid.UUID) bool
- func NormalizePhoneNumber(phoneNumber string, toNormal bool) string
- func ParseMultipartForm(request *http.Request, maxMemory int64) error
- func ParseTimestamp(timestamp string, layout string) (time.Time, error)
- func ReadFileContent(filePath string) (string, error)
- func RemoveDuplicates(slice []string) []string
- func RespondWithJSON(w http.ResponseWriter, statusCode int, payload interface{})
- func RowToMap(rows *sql.Rows) (map[string]any, error)
- func RowsToMaps(rows *sql.Rows) ([]map[string]any, error)
- func SafeDeleteFile(filePath string) error
- func SaveUploadedFile(fileHeader *multipart.FileHeader, destination string) error
- func ToFormatedCurrency(value float64) string
- func ToPlural(word string) string
- func ToSingular(word string) string
- func ToSnakeCase(input string) string
- func TruncateString(s string, maxLength int) string
- func ValidateEmail(email string) bool
- func ValidatePhoneNumber(phoneNumber string) bool
- func ValidateURL(urlString string) bool
- func WrapError(err error, message string) error
- func WrapErrorf(err error, format string, args ...interface{}) error
- func WriteFileContent(filePath string, content string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddToContext ¶ added in v1.3.7
AddToContext adds a key-value pair to context and returns new context.
func CalculateOffset ¶ added in v1.3.7
CalculateOffset calculates database offset for pagination.
func Coalesce ¶ added in v1.3.7
Coalesce returns the first non-empty string from the provided arguments.
func ContainsInt ¶ added in v1.3.7
ContainsInt checks if slice contains integer.
func ContainsString ¶ added in v1.3.7
ContainsString checks if slice contains string.
func ConvertToUUID ¶ added in v1.2.6
ConvertToUUID converts a string to UUID, returns uuid.Nil if conversion fails.
func CreateError ¶
CreateError returns a new error with the given message
func CreateErrorf ¶ added in v1.3.7
CreateErrorf returns a new formatted error with the given message and arguments
func DefaultIfEmpty ¶ added in v1.3.7
DefaultIfEmpty returns the value if not empty, otherwise returns default value.
func DirectoryExists ¶ added in v1.3.7
DirectoryExists checks if a directory exists.
func EnsureDirectory ¶ added in v1.3.7
EnsureDirectory creates directory if it doesn't exist.
func FileExists ¶ added in v1.3.7
FileExists checks if a file exists and is not a directory.
func FormatTimestamp ¶ added in v1.3.7
FormatTimestamp formats timestamp to specified layout.
func GenerateOTP ¶ added in v1.3.5
GenerateOTP generates a random 6-digit OTP.
func GenerateRandomString ¶ added in v1.3.7
GenerateRandomString generates a cryptographically secure random string of specified length.
func GenerateSecureOTPString ¶ added in v1.3.7
GenerateSecureOTPString generates a secure random OTP as string with fixed length.
func GenerateUUID ¶ added in v1.3.7
GenerateUUID generates a new UUID v4.
func GenerateUUIDString ¶ added in v1.3.7
func GenerateUUIDString() string
GenerateUUIDString generates a new UUID v4 as string.
func GetClientIP ¶ added in v1.3.7
GetClientIP extracts client IP address from request.
func GetContextData ¶ added in v1.3.5
GetContextData extracts UUID from request context (alias for GetUUIDContextData).
func GetCurrentTimestamp ¶ added in v1.3.7
GetCurrentTimestamp returns current timestamp in various formats.
func GetCurrentTimestampString ¶ added in v1.3.7
func GetCurrentTimestampString() string
GetCurrentTimestampString returns current timestamp as string in RFC3339 format.
func GetENVBoolValue ¶ added in v1.3.7
GetENVBoolValue loads an environment variable as a boolean with a default value.
func GetENVIntValue ¶ added in v1.3.7
GetENVIntValue loads an environment variable as an integer with a default value.
func GetENVValue ¶
GetENVValue loads the environment variable value for a given key (case insensitive, converts input key to UPPER_SNAKE_CASE), including those loaded from .env file.
func GetENVValueWithDefault ¶ added in v1.3.7
GetENVValueWithDefault loads an environment variable with a default value if not set.
func GetFileSize ¶ added in v1.3.7
GetFileSize returns file size in bytes.
func GetFileType ¶ added in v1.2.6
GetFileType determines if the file is an image, video, document, or unknown.
func GetFormFile ¶ added in v1.3.7
func GetFormFile(request *http.Request, fieldName string) (multipart.File, *multipart.FileHeader, error)
GetFormFile retrieves file from multipart form.
func GetFromContext ¶ added in v1.3.7
func GetFromContext(ctx context.Context, key models.ContextKey) (interface{}, bool)
GetFromContext retrieves value from context with type assertion.
func GetIntContextData ¶ added in v1.3.7
func GetIntContextData(request *http.Request, key models.ContextKey) int
GetIntContextData extracts integer from request context.
func GetIntFromContext ¶ added in v1.3.7
func GetIntFromContext(ctx context.Context, key models.ContextKey) int
GetIntFromContext retrieves integer value from context.
func GetPaginationParams ¶ added in v1.3.7
GetPaginationParams extracts pagination parameters from request.
func GetQueryBool ¶ added in v1.3.7
GetQueryBool extracts a boolean query parameter with optional default value.
func GetQueryID ¶ added in v1.3.5
GetQueryID is an alias for GetQueryUUID for backward compatibility.
func GetQueryInt ¶ added in v1.3.7
GetQueryInt extracts an integer query parameter with optional default value.
func GetQueryParam ¶ added in v1.3.7
GetQueryParam extracts a string query parameter with optional default value.
func GetQueryUUID ¶ added in v1.2.6
GetQueryUUID extracts UUID from query parameter "id".
func GetSearchKeyword ¶ added in v1.2.6
GetSearchKeyword extracts search keyword from query parameter "keyword".
func GetStringContextData ¶ added in v1.2.6
func GetStringContextData(request *http.Request, key models.ContextKey) string
GetStringContextData extracts string from request context.
func GetStringFromContext ¶ added in v1.3.7
func GetStringFromContext(ctx context.Context, key models.ContextKey) string
GetStringFromContext retrieves string value from context.
func GetUUIDContextData ¶ added in v1.2.6
GetUUIDContextData extracts UUID from request context.
func GetUserAgent ¶ added in v1.3.7
GetUserAgent extracts user agent from request.
func IsDocumentFile ¶ added in v1.3.7
IsDocumentFile checks if the file is a document based on extension.
func IsImageFile ¶ added in v1.3.7
IsImageFile checks if the file is an image based on extension.
func IsValidUUID ¶ added in v1.3.0
IsValidUUID checks if the provided string is a valid UUID.
func IsVideoFile ¶ added in v1.3.7
IsVideoFile checks if the file is a video based on extension.
func IsZeroUUID ¶ added in v1.3.0
IsZeroUUID checks if UUID is the zero value.
func NormalizePhoneNumber ¶ added in v1.2.6
NormalizePhoneNumber normalizes phone numbers to standard format.
func ParseMultipartForm ¶ added in v1.3.7
ParseMultipartForm parses multipart form with size limits.
func ParseTimestamp ¶ added in v1.3.7
ParseTimestamp parses timestamp string with specified layout.
func ReadFileContent ¶ added in v1.3.7
ReadFileContent reads entire file content as string.
func RemoveDuplicates ¶ added in v1.3.7
RemoveDuplicates removes duplicate values from string slice.
func RespondWithJSON ¶
func RespondWithJSON(w http.ResponseWriter, statusCode int, payload interface{})
RespondWithJSON writes a JSON response to the HTTP response writer. Constructs a standardized server response with payload and success flag. Sets the appropriate headers, status code, and writes the JSON data.
func SafeDeleteFile ¶ added in v1.3.7
SafeDeleteFile safely deletes a file with error handling.
func SaveUploadedFile ¶ added in v1.3.7
func SaveUploadedFile(fileHeader *multipart.FileHeader, destination string) error
SaveUploadedFile saves uploaded file to specified path.
func ToFormatedCurrency ¶ added in v1.3.9
func ToSingular ¶ added in v1.3.9
func ToSnakeCase ¶ added in v1.4.0
func TruncateString ¶ added in v1.3.7
TruncateString truncates string to specified length with ellipsis.
func ValidateEmail ¶ added in v1.3.7
ValidateEmail validates an email address format.
func ValidatePhoneNumber ¶ added in v1.3.7
ValidatePhoneNumber validates phone number format.
func ValidateURL ¶ added in v1.3.7
ValidateURL validates a URL format.
func WrapErrorf ¶ added in v1.3.7
WrapErrorf wraps an existing error with formatted additional context
func WriteFileContent ¶ added in v1.3.7
WriteFileContent writes string content to file.
Types ¶
This section is empty.