ginutil

package
v0.1.26 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ginutil provides utility functions for working with Gin HTTP framework.

Index

Constants

This section is empty.

Variables

View Source
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

func BindJSON(c *gin.Context, obj any) error

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

func ErrorResponse(ctx *gin.Context, errorInfo *ErrorInfo)

ErrorResponse creates a standardized RFC 9457 error response.

func GetErrorTypeURI added in v0.1.24

func GetErrorTypeURI(c *gin.Context) string

GetErrorTypeURI constructs a standardized error type URI.

func GetQueryInt64

func GetQueryInt64(c *gin.Context, key string, defaultValue int64) (int64, error)

GetQueryInt64 retrieves an int64 query parameter from the Gin context.

func HandleDomainError added in v0.1.24

func HandleDomainError(ctx *gin.Context, err error, fallbackMessage string)

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

func InternalServerError(ctx *gin.Context, err error, detail string)

InternalServerError creates an error response for internal server errors.

func InvalidPathParamError added in v0.1.24

func InvalidPathParamError(ctx *gin.Context, paramName, value string, message string)

InvalidPathParamError creates an error response for invalid path parameters.

func InvalidQueryParamError added in v0.1.24

func InvalidQueryParamError(ctx *gin.Context, paramName, value string, message string)

InvalidQueryParamError creates an error response for invalid query parameters.

func InvalidRequestBodyError added in v0.1.24

func InvalidRequestBodyError(ctx *gin.Context, err error)

InvalidRequestBodyError creates an error response for invalid request body.

func ParseInt64 added in v0.1.24

func ParseInt64(c *gin.Context, paramName string, defaultValue int64) (int64, error)

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

func ParseString(c *gin.Context, paramName string, required bool) (string, error)

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

func ParseUUID(c *gin.Context, paramName string) (uuid.UUID, error)

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

func ResourceNotFoundError(ctx *gin.Context, resourceType, identifier string)

ResourceNotFoundError creates a standardized 404 error response.

Types

type ErrorInfo added in v0.1.24

type ErrorInfo struct {
	Type     ErrorType
	Message  string
	Location string
	Value    any
	Err      error
}

ErrorInfo contains information about an error.

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
)

Jump to

Keyboard shortcuts

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