Documentation
¶
Index ¶
- func Adapt[Req any, Resp any](adapter *Adapter, mode BindMode, handler HandlerFunc[Req, Resp]) gin.HandlerFunc
- func BadRequestError(message string, cause error) error
- func ConflictError(message string, cause error) error
- func ErrorWithCode(status int, code, message string, details map[string]any) error
- func ForbiddenError(message string) error
- func InternalError(message string, cause error) error
- func NormalizeAllowedChannelIDs(v any) ([]uint, error)
- func NormalizePagination(page, pageSize int) (int, int)
- func NotFoundError(message string) error
- func StatusEqualsEnabled(v any) bool
- func UnauthorizedError(message string) error
- func ValidateAllowedChannelIDs(ids []uint) error
- func ValidateStatusValue(v any) error
- type APIError
- type Adapter
- type BindMode
- type BodyMapSetter
- type BodyProvider
- type ContextFactory
- type Created
- type DefaultContextFactory
- type DefaultErrorMapper
- type DefaultRequestBinder
- type EmptyRequest
- type ErrorMapper
- type HandlerFunc
- type IDPathRequest
- type JSONWriter
- type PaginatedResponse
- type PaginationQuery
- type RequestBinder
- type ResponseWriter
- type StatusCoder
- type StatusResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Adapt ¶
func Adapt[Req any, Resp any](adapter *Adapter, mode BindMode, handler HandlerFunc[Req, Resp]) gin.HandlerFunc
func BadRequestError ¶
func ConflictError ¶
func ErrorWithCode ¶
ErrorWithCode 用于需要结构化错误响应的端点(按 code 做前端 i18n)。
func ForbiddenError ¶
func InternalError ¶
func NormalizeAllowedChannelIDs ¶
NormalizeAllowedChannelIDs converts an arbitrary JSON value (typically from a map[string]any update payload) into []uint, rejecting non-array or non-integer / negative values. A nil input returns nil, nil.
func NormalizePagination ¶
func NotFoundError ¶
func StatusEqualsEnabled ¶ added in v0.0.6
StatusEqualsEnabled reports whether v decodes to consts.StatusEnabled. Call only after ValidateStatusValue has confirmed v is a legal status.
func UnauthorizedError ¶
func ValidateAllowedChannelIDs ¶
ValidateAllowedChannelIDs validates a slice of channel IDs for token / token_template / user_group. Returns error if length > 100 or any ID is zero.
func ValidateStatusValue ¶
ValidateStatusValue checks that the provided value is a valid status (consts.StatusEnabled or consts.StatusDisabled). The value may come from a JSON-decoded map[string]any (float64) or from a typed int field.
Types ¶
type APIError ¶
type Adapter ¶
type Adapter struct {
ContextFactory ContextFactory
Binder RequestBinder
Writer ResponseWriter
ErrorMapper ErrorMapper
}
func NewAdapter ¶
func NewAdapter(settings *config.MasterRuntimeConfig, logger *zap.Logger, application app.Application) *Adapter
type BodyMapSetter ¶
type BodyProvider ¶
type BodyProvider interface {
Body() any
}
type DefaultContextFactory ¶
type DefaultContextFactory struct {
Settings *config.MasterRuntimeConfig
Logger *zap.Logger
App app.Application
}
type DefaultErrorMapper ¶
type DefaultErrorMapper struct{}
type DefaultRequestBinder ¶
type DefaultRequestBinder struct{}
type EmptyRequest ¶
type EmptyRequest struct{}
type ErrorMapper ¶
type IDPathRequest ¶
type IDPathRequest struct {
ID string `uri:"id" binding:"required"`
}
type JSONWriter ¶
type JSONWriter struct{}
type PaginatedResponse ¶
type PaginationQuery ¶
type StatusCoder ¶
type StatusCoder interface {
StatusCode() int
}
type StatusResponse ¶
type StatusResponse struct {
Status string `json:"status"`
}