Documentation ¶
Index ¶
- Constants
- func BadRequest(format string, obj ...any) error
- func Code(code int32, detail string) error
- func CodeFormat(code int32, format string, args ...any) error
- func Conflict(format string, obj ...any) error
- func Equal(err1 error, err2 error) bool
- func Forbidden(format string, obj ...any) error
- func InternalServerError(format string, obj ...any) error
- func LookupID(code int32) (string, bool)
- func MethodNotAllowed(format string, obj ...any) error
- func New(id string, code int32, detail string) error
- func NewFormat(id string, code int32, format string, args ...any) error
- func NotFound(format string, obj ...any) error
- func RegisterCode(code int32, id string)
- func RequestEntityTooLarge(format string, obj ...any) error
- func Timeout(format string, obj ...any) error
- func TooManyRequests(format string, obj ...any) error
- func Unauthorized(format string, obj ...any) error
- type Error
Constants ¶
const ( UnknownID = "http.response.status.unknown" // ID for Unknown status BadRequestID = "http.response.status.bad_request" // ID for Bad Request status ForbiddenID = "http.response.status.forbidden" // ID for Forbidden status NotFoundID = "http.response.status.not_found" // ID for Not Found status MethodNotAllowedID = "http.response.status.method_not_allowed" // ID for Method Not Allowed status TooManyRequestsID = "http.response.status.too_many_requests" // ID for Too Many Requests status RequestEntityTooLargeID = "http.response.status.request_entity_too_large" // ID for Request Entity Too Large status InternalServerErrorID = "http.response.status.internal_server_error" // ID for Internal Server Error status ConflictID = "http.response.status.conflict" // ID for Conflict status RequestTimeoutID = "http.response.status.request_timeout" // ID for Request Timeout status )
Define constant IDs for various Error status codes
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶
BadRequest generates a 400 error.
func CodeFormat ¶
CodeFormat generates an error for a given code
func InternalServerError ¶
InternalServerError generates a 500 error.
func LookupID ¶
LookupID looks up the identifier corresponding to the given code. This function uses a read lock to ensure safe concurrent access to shared resources. Parameters: code - The integer value of the code to look up.
Returns: The string identifier corresponding to the code.
func MethodNotAllowed ¶
MethodNotAllowed generates a 405 error.
func RegisterCode ¶
RegisterCode register a new error code with the given ID,or overwriting any existing one
func RequestEntityTooLarge ¶
RequestEntityTooLarge generates a 413 error.
func TooManyRequests ¶
TooManyRequests generates a 429 error.
func Unauthorized ¶
Unauthorized generates a 401 error.
Types ¶
type Error ¶
type Error struct { ID string `json:"id,omitempty"` Code int32 `json:"code,omitempty"` Detail string `json:"detail,omitempty"` }
Error customize the error structure for implementation errors.Error interface
func Parse ¶
Parse tries to parse a JSON string into an error. If that fails, it will set the given string as the error detail.