Documentation
¶
Overview ¶
Package ginutil provides utility functions for working with Gin HTTP framework.
Index ¶
- Variables
- func BindJSON(c *gin.Context, obj any) error
- 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 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 ¶ added in v0.1.24
BindJSON binds JSON request body and validates it. Returns error if validation fails - caller must handle error response.
func ErrorResponse ¶ added in v0.1.24
ErrorResponse creates a standardized RFC 9457 error response.
func GetErrorTypeURI ¶ added in v0.1.24
GetErrorTypeURI constructs a standardized error type URI.
func GetQueryInt64 ¶
GetQueryInt64 retrieves an int64 query parameter from the Gin context.
func HandleDomainError ¶ added in v0.1.24
HandleDomainError handles domain-specific errors and returns appropriate HTTP responses.
func HandleValidationError ¶ added in v0.1.24
func HandleValidationError(gCtx *gin.Context, paramName, paramValue string, err error, isPathParam bool)
HandleValidationError handles validation errors and sends appropriate RFC 9457 response.
func InternalServerError ¶ added in v0.1.24
InternalServerError creates an error response for internal server errors.
func InvalidPathParamError ¶ added in v0.1.24
InvalidPathParamError creates an error response for invalid path parameters.
func InvalidQueryParamError ¶ added in v0.1.24
InvalidQueryParamError creates an error response for invalid query parameters.
func InvalidRequestBodyError ¶ added in v0.1.24
InvalidRequestBodyError creates an error response for invalid request body.
func ParseInt64 ¶ added in v0.1.24
ParseInt64 parses int64 from query parameter and validates it. Returns error if validation fails - caller must handle error response.
func ParseString ¶ added in v0.1.24
ParseString parses string from parameter and validates it's not empty. Returns error if validation fails - caller must handle error response.
func ParseUUID ¶ added in v0.1.24
ParseUUID parses UUID from context parameter and validates it. Returns error if validation fails - caller must handle error response.
func ResourceNotFoundError ¶ added in v0.1.24
ResourceNotFoundError creates a standardized 404 error response.
Types ¶
type ErrorType ¶ added in v0.1.24
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 )