Documentation
¶
Index ¶
- Variables
- func Handle[T any](h HandlerFunc[T]) gin.HandlerFunc
- func SetHookerAfterResponse(h func(ctx *gin.Context, response Response))
- func SetHookerBeforeResponse(h func(ctx *gin.Context, response Response) (stop bool))
- func SetHookerBindingError(h func(ctx *gin.Context, err error))
- func SetHookerTransformResponse(h func(response Response) any)
- func SetValidatorMaxDepth(depth int)
- func Wrap(handler func(ctx *Context) Response) gin.HandlerFunc
- type ContentType
- type Context
- type HandlerFunc
- type IValidator
- type Response
- func (r Response) WithCode(code int) Response
- func (r Response) WithContentType(typ ContentType) Response
- func (r Response) WithData(data any) Response
- func (r Response) WithError(err error) Response
- func (r Response) WithErrors(errors ...error) Response
- func (r Response) WithHeader(key, val string) Response
- func (r Response) WithHeaders(kv map[string]string) Response
- func (r Response) WithHtmlPath(htmlPath string) Response
- func (r Response) WithHttpStatus(status int) Response
- func (r Response) WithMsg(msg string) Response
- type Validator
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ValidatorMaxDepth defines the recursion limit for the validation engine. ValidatorMaxDepth = 20 // ErrMaxDepth is returned when the validation exceeds ValidatorMaxDepth. ErrMaxDepth = errors.New("xgin.validator: maximum recursion depth exceeded") // HookerBindingError is triggered on AutoBind or IValidator failures. HookerBindingError func(ctx *gin.Context, err error) // HookerTransformResponse modifies the Response object before final rendering. HookerTransformResponse func(response Response) any // HookerBeforeResponse executes before rendering; return true to abort. HookerBeforeResponse func(ctx *gin.Context, response Response) (stop bool) // HookerAfterResponse executes after the response has been written. HookerAfterResponse func(ctx *gin.Context, response Response) )
Global Configuration and Lifecycle Hooks
Functions ¶
func Handle ¶
func Handle[T any](h HandlerFunc[T]) gin.HandlerFunc
Handle wraps business logic with automated binding, deep validation, and lifecycle hooks.
func SetHookerAfterResponse ¶
func SetHookerBeforeResponse ¶
func SetHookerBindingError ¶
func SetValidatorMaxDepth ¶
func SetValidatorMaxDepth(depth int)
Types ¶
type ContentType ¶
type ContentType int8
const ( ContentTypeJSON ContentType = iota ContentTypeIndentedJSON ContentTypeSecureJSON ContentTypeJsonpJSON ContentTypeAsciiJSON ContentTypePureJSON ContentTypeMsgPack ContentTypeProtoBuf ContentTypeRedirect ContentTypeString ContentTypeTOML ContentTypeXML ContentTypeYAML ContentTypeHTML )
type Context ¶
Context wraps gin.Context to provide extended functionality
func NewContext ¶
NewContext creates a new xgin Context from a gin Context
type HandlerFunc ¶
HandlerFunc defines the signature for type-safe generic handlers with request DTO.
type IValidator ¶
type IValidator interface {
Validate() error
}
IValidator defines the interface for custom business logic validation.
type Response ¶
type Response struct {
HttpStatus int `json:"-"`
Code int `json:"code"`
Msg string `json:"msg"`
Data any `json:"data"`
Header map[string]string `json:"-"`
Errors []error `json:"-"`
ContentType ContentType `json:"-"`
HtmlPath string `json:"-"`
}
func (Response) WithContentType ¶
func (r Response) WithContentType(typ ContentType) Response
func (Response) WithErrors ¶
func (Response) WithHeader ¶
func (Response) WithHtmlPath ¶
func (Response) WithHttpStatus ¶
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator handles recursive validation with metadata caching.
func NewValidator ¶
NewValidator creates a new validator instance with a specified depth limit.
func SharedValidator ¶
SharedValidator returns a global singleton validator.
Click to show internal directories.
Click to hide internal directories.