utils

package
v0.0.0-...-0e20228 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIResponse

func APIResponse(c *gin.Context, status int, message string, data interface{})

APIResponse returns a success response with data

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

CheckPasswordHash membandingkan password dengan hash

func CompareHashAndPassword

func CompareHashAndPassword(hashedPassword, password string) error

CompareHashAndPassword is a wrapper around bcrypt's CompareHashAndPassword that returns a more user-friendly error message

func ErrorResponse

func ErrorResponse(c *gin.Context, status int, message string)

ErrorResponse returns an error response

func GenerateSecureToken

func GenerateSecureToken() (string, error)

GenerateSecureToken generates a cryptographically secure token for various purposes (like password reset, email verification, etc.)

func HasMaxLength

func HasMaxLength(fieldName, value string, maxLength int) error

HasMaxLength validates if a string doesn't exceed the maximum length

func HasMinLength

func HasMinLength(fieldName, value string, minLength int) error

HasMinLength validates if a string meets the minimum length

func HashPassword

func HashPassword(password string) (string, error)

HashPassword mengenkripsi password dengan bcrypt

func IsHashedPassword

func IsHashedPassword(str string) bool

IsHashedPassword checks if a string is already a bcrypt hash

func IsValidEmail

func IsValidEmail(email string) bool

IsValidEmail checks if the email has a valid format (returns boolean)

func NotFoundResponse

func NotFoundResponse(c *gin.Context, message string)

NotFoundResponse returns a standardized not found response

func StringToUUID

func StringToUUID(id string) (uuid.UUID, error)

StringToUUID converts a string to UUID and validates it

func ValidateEmail

func ValidateEmail(email string) error

ValidateEmail memastikan format email valid

func ValidateNotEmpty

func ValidateNotEmpty(fieldName, value string) error

ValidateNotEmpty validates if a string is not empty

func ValidatePassword

func ValidatePassword(password string) error

ValidatePassword validates a password with stricter rules

func ValidateURL

func ValidateURL(rawURL string) error

ValidateURL validates if a string is a valid URL

func ValidateUUID

func ValidateUUID(id string) error

ValidateUUID validates if a string is a valid UUID

func ValidateUsername

func ValidateUsername(username string) error

ValidateUsername validates a username

func ValidationErrorResponse

func ValidationErrorResponse(c *gin.Context, message string, errors interface{})

ValidationErrorResponse returns a standardized validation error response

Types

type Response

type Response struct {
	Success bool        `json:"success"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
	Error   string      `json:"error,omitempty"`
}

Response represents a standardized API response

Jump to

Keyboard shortcuts

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