validation

package
v0.0.0-...-9dddd53 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisplayPatches

func DisplayPatches[T any](original T, updated T) (diff.PatchLog, error)

DisplayPatches generates and applies patches to reflect the differences between the original and updated values.

func FormatString

func FormatString(str string) string

FormatString takes an input string, replaces all occurrences of "-" with "", and converts the string to lowercase, returning the transformed result.

func HandleError

func HandleError(ctx *fiber.Ctx, status int, cause string, errors []ErrorObject) error

HandleError generates and sends a JSON error response based on the given status, cause, and error details. It handles specific error cases like unknown routes, invalid UUIDs, or API key issues. The response contains metadata like request ID and documentation URL for debugging.

func IsValidUuid

func IsValidUuid(uuidAsString string) bool

IsValidUuid checks if the given string is a valid UUID. The function returns false for nil UUIDs or if the string does not conform to the UUID format.

func ParseBody

func ParseBody[T any](ctx *fiber.Ctx) (T, error)

ParseBody parses the HTTP request body into a generic type T and returns the result or an error if parsing fails.

func RemoveDuplicateFromArray

func RemoveDuplicateFromArray(strings []string) []string

RemoveDuplicateFromArray removes duplicate strings from a slice and returns a new slice with unique elements in the order of their first appearance. Deprecated: RemoveDuplicateFromArray Moved from validation to utils package. Use utils.RemoveStringDuplicates instead. This function will be removed without warning.

func RemoveDuplicateWords

func RemoveDuplicateWords(input string) string

RemoveDuplicateWords removes duplicate words from the input string while preserving their order. It treats the "|" character as a special case, ensuring it is retained in the result irrespective of duplicates.

func ToTimePointer

func ToTimePointer(t time.Time) *time.Time

ToTimePointer converts a time.Time value to a pointer to that value.

Types

type ErrorHandlerType

type ErrorHandlerType = string

ErrorHandlerType constants representing common error messages.

const (
	// InvalidApiKey indicates an invalid API key error.
	InvalidApiKey ErrorHandlerType = "Invalid API Key"
	// InvalidUuid indicates an invalid UUID error.
	InvalidUuid ErrorHandlerType = "Invalid UUID"
	// InvalidToken indicates an invalid token error.
	InvalidToken ErrorHandlerType = "Invalid Token"
	// NotEnoughPermission indicates a permission-related error.
	NotEnoughPermission ErrorHandlerType = "Not Enough Permission"
)

type ErrorObject

type ErrorObject struct {
	Name            string `json:"name"`
	Reason          string `json:"reason"`
	DeveloperReason string `json:"developer_reason"`
	Code            int    `json:"code"`
}

ErrorObject represents a structured error with a name, user-facing reason, developer-facing reason, and an associated error code.

type ErrorResponse

type ErrorResponse struct {
	Success       bool          `json:"success"`
	Code          int           `json:"code"`
	Cause         string        `json:"cause"`
	Extra         []ErrorObject `json:"extra"`
	Documentation string        `json:"documentation"`
	MsTime        int64         `json:"msTime"`
}

ErrorResponse represents the structure of an API error response, including success, error code, cause, additional error details, documentation URL, and response time in milliseconds.

Jump to

Keyboard shortcuts

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