Documentation
¶
Index ¶
- func AuthMethodFrom(c echo.Context) string
- func HasScope(c echo.Context, expected string) bool
- func IsAdmin(c echo.Context) bool
- func SendError(c echo.Context, err error) error
- func UserIDFrom(c echo.Context) string
- type CtxKey
- type ErrorBody
- type ErrorCode
- type ErrorResponse
- type HTTPError
- func BadRequest(msg string) *HTTPError
- func Conflict(msg string) *HTTPError
- func Forbidden(msg string) *HTTPError
- func Internal(msg string) *HTTPError
- func NewError(status int, code ErrorCode, message string) *HTTPError
- func NotFound(msg string) *HTTPError
- func PermissionDenied(permission string, resource ...string) *HTTPError
- func RateLimited(msg string) *HTTPError
- func ServiceUnavailable(msg string) *HTTPError
- func Unauthorized(msg string) *HTTPError
- func Unprocessable(msg string) *HTTPError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthMethodFrom ¶
AuthMethodFrom 返回当前请求的鉴权方式:'jwt' / 'user_token' / ”(未鉴权)。 HybridAuthMiddleware 命中后设置。
func HasScope ¶
HasScope reports whether the authenticated User Token carries a required permission.
func UserIDFrom ¶
UserIDFrom 从 echo.Context 取出 user_id(鉴权中间件设置)。
Types ¶
type ErrorBody ¶
type ErrorBody struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Details any `json:"details,omitempty"`
}
ErrorBody 错误正文。
type ErrorCode ¶
type ErrorCode string
ErrorCode 标准化错误码(见 docs/13 附录 A)。
const ( CodeBadRequest ErrorCode = "BAD_REQUEST" CodeForbidden ErrorCode = "FORBIDDEN" CodePermissionDenied ErrorCode = "PERMISSION_DENIED" CodePermissionExpansionRequiresNewToken ErrorCode = "PERMISSION_EXPANSION_REQUIRES_NEW_TOKEN" CodeNotFound ErrorCode = "NOT_FOUND" CodeConflict ErrorCode = "CONFLICT" CodeUnprocessable ErrorCode = "VALIDATION_FAILED" CodeRateLimited ErrorCode = "RATE_LIMITED" CodeInternal ErrorCode = "INTERNAL_ERROR" )
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorBody `json:"error"`
}
ErrorResponse 统一错误响应体。
{ "error": { "code": "...", "message": "..." } }
type HTTPError ¶
HTTPError 业务级 HTTP 错误。
func BadRequest ¶
func PermissionDenied ¶ added in v0.1.41
func RateLimited ¶
func ServiceUnavailable ¶
func Unauthorized ¶
func Unprocessable ¶
Click to show internal directories.
Click to hide internal directories.