Documentation
¶
Index ¶
- func DisplayPatches[T any](original T, updated T) (diff.PatchLog, error)
- func FormatString(str string) string
- func HandleError(ctx *fiber.Ctx, status int, cause string, errors []ErrorObject) error
- func IsValidUuid(uuidAsString string) bool
- func ParseBody[T any](ctx *fiber.Ctx) (T, error)
- func RemoveDuplicateFromArray(strings []string) []string
- func RemoveDuplicateWords(input string) string
- func ToTimePointer(t time.Time) *time.Time
- type ErrorHandlerType
- type ErrorObject
- type ErrorResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisplayPatches ¶
DisplayPatches generates and applies patches to reflect the differences between the original and updated values.
func FormatString ¶
FormatString takes an input string, replaces all occurrences of "-" with "", and converts the string to lowercase, returning the transformed result.
func HandleError ¶
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 ¶
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 ¶
ParseBody parses the HTTP request body into a generic type T and returns the result or an error if parsing fails.
func RemoveDuplicateFromArray ¶
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 ¶
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.
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.