ginutil

package
v0.1.41 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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 ConflictError

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

ConflictError creates a standardized 409 Conflict error response.

func ErrorResponse

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

ErrorResponse creates a standardized RFC 9457 error response.

func GetErrorTypeURI

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

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

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

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

InternalServerError creates an error response for internal server errors.

func InvalidPathParamError

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

InvalidPathParamError creates an error response for invalid path parameters.

func InvalidQueryParamError

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

InvalidQueryParamError creates an error response for invalid query parameters.

func InvalidRequestBodyError

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

InvalidRequestBodyError creates an error response for invalid request body.

func ParseBool

func ParseBool(c *gin.Context, paramName string, defaultValue bool) (bool, error)

ParseBool parses bool from query parameter and validates it. Returns error if validation fails - caller must handle error response.

func ParseInt64

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

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

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

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

ResourceNotFoundError creates a standardized 404 error response.

Types

type ErrorInfo

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

ErrorInfo contains information about an error.

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
)

Jump to

Keyboard shortcuts

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