Documentation
¶
Overview ¶
Package ginutil provides utility functions for working with Gin HTTP framework.
Index ¶
- Variables
- func BindJSON(c *gin.Context, obj any) error
- func ConflictError(ctx *gin.Context, err error, detail string)
- func ErrorResponse(ctx *gin.Context, errorInfo *ErrorInfo)
- func GetErrorTypeURI(c *gin.Context) string
- func GetQueryInt64(c *gin.Context, key string, defaultValue int64) (int64, error)
- func HandleDomainError(ctx *gin.Context, err error, fallbackMessage string)
- func HandleValidationError(gCtx *gin.Context, paramName, paramValue string, err error, isPathParam bool)
- func InternalServerError(ctx *gin.Context, err error, detail string)
- func InvalidPathParamError(ctx *gin.Context, paramName, value string, message string)
- func InvalidQueryParamError(ctx *gin.Context, paramName, value string, message string)
- func InvalidRequestBodyError(ctx *gin.Context, err error)
- func ParseBool(c *gin.Context, paramName string, defaultValue bool) (bool, error)
- func ParseInt64(c *gin.Context, paramName string, defaultValue int64) (int64, error)
- func ParseString(c *gin.Context, paramName string, required bool) (string, error)
- func ParseUUID(c *gin.Context, paramName string) (uuid.UUID, error)
- func ResourceNotFoundError(ctx *gin.Context, resourceType, identifier string)
- type ErrorInfo
- type ErrorType
Constants ¶
This section is empty.
Variables ¶
var ( ErrValidationFailed = errors.New("validation failed") ErrRequiredParam = errors.New("required parameter is missing") ErrInvalidFormat = errors.New("invalid parameter format") ErrInvalidValue = errors.New("invalid parameter value") )
Validation error types.
Functions ¶
func BindJSON ¶
BindJSON binds JSON request body and validates it. Returns error if validation fails - caller must handle error response.
func ConflictError ¶
ConflictError creates a standardized 409 Conflict error response.
func ErrorResponse ¶
ErrorResponse creates a standardized RFC 9457 error response.
func GetErrorTypeURI ¶
GetErrorTypeURI constructs a standardized error type URI.
func GetQueryInt64 ¶
GetQueryInt64 retrieves an int64 query parameter from the Gin context.
func HandleDomainError ¶
HandleDomainError handles domain-specific errors and returns appropriate HTTP responses.
func HandleValidationError ¶
func HandleValidationError(gCtx *gin.Context, paramName, paramValue string, err error, isPathParam bool)
HandleValidationError handles validation errors and sends appropriate RFC 9457 response.
func InternalServerError ¶
InternalServerError creates an error response for internal server errors.
func InvalidPathParamError ¶
InvalidPathParamError creates an error response for invalid path parameters.
func InvalidQueryParamError ¶
InvalidQueryParamError creates an error response for invalid query parameters.
func InvalidRequestBodyError ¶
InvalidRequestBodyError creates an error response for invalid request body.
func ParseBool ¶
ParseBool parses bool from query parameter and validates it. Returns error if validation fails - caller must handle error response.
func ParseInt64 ¶
ParseInt64 parses int64 from query parameter and validates it. Returns error if validation fails - caller must handle error response.
func ParseString ¶
ParseString parses string from parameter and validates it's not empty. Returns error if validation fails - caller must handle error response.
func ParseUUID ¶
ParseUUID parses UUID from context parameter and validates it. Returns error if validation fails - caller must handle error response.
func ResourceNotFoundError ¶
ResourceNotFoundError creates a standardized 404 error response.
Types ¶
type ErrorType ¶
type ErrorType int
ErrorType represents common error types.
const ( // ErrorTypeInvalidQuery for query parameter validation errors. ErrorTypeInvalidQuery ErrorType = iota // ErrorTypeInvalidPath for path parameter validation errors. ErrorTypeInvalidPath // ErrorTypeInvalidRequestBody for request body validation errors. ErrorTypeInvalidRequestBody // ErrorTypeResourceNotFound for resource not found errors. ErrorTypeResourceNotFound // ErrorTypeInternalServer for internal server errors. ErrorTypeInternalServer )