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 MapChannelFileError(err error) error
- func NewPostCommitPublishContext(requestCtx context.Context) (context.Context, context.CancelFunc)
- func NormalizeAllowedChannelIDs(v any) ([]uint, error)
- func NormalizeAllowedGroupIDs(v any) ([]uint, error)
- func NormalizePagination(page, pageSize int) (int, int)
- func NotFoundError(message string) error
- func ParseChannelImportDryRun(raw string) (bool, error)
- func ParseTopN(raw int) (int, error)
- func ResolveGroupID(q dao.AdminQuery, userID uint) (uint, error)
- func SetAttachmentHeaders(c *gin.Context, filename string)
- func StatusEqualsEnabled(v any) bool
- func UnauthorizedError(message string) error
- func ValidateAllowedChannelIDs(ids []uint) error
- func ValidateAllowedGroupIDs(ids []uint) error
- func ValidateAutoBanValue(v any) error
- func ValidateStatusValue(v any) error
- func WriteMappedError(adapter *Adapter, c *gin.Context, err error)
- type APIError
- type Accepted
- type Adapter
- type BindMode
- type BodyMapSetter
- type BodyProvider
- type ContextFactory
- type Created
- type DefaultContextFactory
- type DefaultErrorMapper
- type DefaultRequestBinder
- type EmptyRequest
- type ErrorMapper
- type HTTPResponse
- 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 MapChannelFileError ¶ added in v0.0.13
func NewPostCommitPublishContext ¶ added in v0.0.16
NewPostCommitPublishContext keeps request-scoped values while giving authoritative post-commit queries and events their own bounded lifetime.
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 NormalizeAllowedGroupIDs ¶ added in v0.0.8
NormalizeAllowedGroupIDs 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 ParseChannelImportDryRun ¶ added in v0.0.13
func ResolveGroupID ¶ added in v0.0.8
func ResolveGroupID(q dao.AdminQuery, userID uint) (uint, error)
ResolveGroupID 返回 userID 所属用户组 ID。查不到用户时返回 (0, err)。 放在 api 包供 token / token_template 等子包共用;只依赖 dao,不依赖 middleware。
func SetAttachmentHeaders ¶ added in v0.0.13
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 ValidateAllowedGroupIDs ¶ added in v0.0.8
ValidateAllowedGroupIDs validates a slice of user-group IDs for token_template. Returns error if length > 100 or any ID is zero.
func ValidateAutoBanValue ¶ added in v0.0.15
ValidateAutoBanValue 保证 auto_ban 与渠道 status 使用相同的严格 0/1 契约。 map JSON 解码后的数字可以是 float64,但仍必须是精确的二态整数。
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 Accepted ¶ added in v0.0.13
type Accepted[T any] struct { Body T }
func (Accepted[T]) HTTPStatus ¶ added in v0.0.13
func (Accepted[T]) ResponseBody ¶ added in v0.0.13
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 HTTPResponse ¶ added in v0.0.13
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"`
}