helper

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Capitalize

func Capitalize(s string) string

Capitalize capitalizes the first letter of a string

func Contains

func Contains(slice any, item any) bool

Contains checks if a slice contains a value

func ErrToString

func ErrToString(err error) string

errToString converts an error to a string, returning "nil" if error is nil

func FiberLoggerOutput

func FiberLoggerOutput(str string) io.Writer

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration as a human-readable string

func FromJSON

func FromJSON(jsonStr string, v any) error

FromJSON converts a JSON string to an interface

func GenerateID

func GenerateID() (string, error)

GenerateID generates a unique ID

func GenerateUUID

func GenerateUUID() (string, error)

GenerateUUID generates a UUID

func GetClientIP

func GetClientIP(r *http.Request) string

GetClientIP gets the client IP address from a request

func HashPassword

func HashPassword(password string) string

HashPassword hashes a password (placeholder - implement actual hashing)

func IsValidUUID

func IsValidUUID(uuid string) bool

IsValidUUID checks if a string is a valid UUID

func JSONMarshal

func JSONMarshal(v interface{}) ([]byte, error)

func JSONMarshalIndent

func JSONMarshalIndent(v interface{}, prefix, indent string) ([]byte, error)

func JSONMarshalNoEscape

func JSONMarshalNoEscape(v interface{}) ([]byte, error)

func JSONUnmarshal

func JSONUnmarshal(data []byte, v interface{}) error

func MapToStruct

func MapToStruct(data map[string]any, result any) error

MapToStruct converts a map to a struct

func NewPaginatedResponse

func NewPaginatedResponse(data any, pagination Pagination) out.Response

NewPaginatedResponse creates a paginated response

func RemoveDuplicates

func RemoveDuplicates(slice any) any

RemoveDuplicates removes duplicate values from a slice

func Retry

func Retry(fn func() error, maxRetries int, initialDelay time.Duration) error

Retry retries a function with exponential backoff

func SanitizeString

func SanitizeString(input string) string

SanitizeString sanitizes a string by removing potentially harmful characters

func StringPtr

func StringPtr(s string) *string

Helper function to convert string pointer to string pointer

func StructToMap

func StructToMap(obj any) (map[string]any, error)

StructToMap converts a struct to a map

func ToCamelCase

func ToCamelCase(s string) string

ToCamelCase converts a string to camelCase

func ToIndentJSON

func ToIndentJSON(v any) (string, error)

func ToJSON

func ToJSON(v any) (string, error)

ToJSON converts an interface to JSON string

func ToLogJSON

func ToLogJSON(v any) string

func ToSnakeCase

func ToSnakeCase(s string) string

ToSnakeCase converts a string to snake_case

func Truncate

func Truncate(s string, length int) string

Truncate truncates a string to a specified length

func ValidateEmail

func ValidateEmail(email string) bool

ValidateEmail validates an email address

func ValidatePhone

func ValidatePhone(phone string) bool

ValidatePhone validates a phone number

Types

type Filter

type Filter struct {
	Field    string `json:"field" form:"field"`
	Operator string `json:"operator" form:"operator"`
	Value    any    `json:"value" form:"value"`
}

Filter represents query filter parameters

type Pagination

type Pagination struct {
	Page       int `json:"page" form:"page"`
	PageSize   int `json:"page_size" form:"page_size"`
	Total      int `json:"total"`
	TotalPages int `json:"total_pages"`
}

Pagination represents pagination parameters

func Paginate

func Paginate(data any, page, pageSize int) (any, Pagination)

Paginate applies pagination to a slice

type Sort

type Sort struct {
	Field     string `json:"field" form:"field"`
	Direction string `json:"direction" form:"direction"` // "asc" or "desc"
}

Sort represents sorting parameters

Jump to

Keyboard shortcuts

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