Documentation ¶
Index ¶
- func As(err error, target interface{}) bool
- func Code(err error) codes.Code
- func Domain(err error) string
- func Is(err, target error) bool
- func IsBadRequest(err error) bool
- func IsConflict(err error) bool
- func IsForbidden(err error) bool
- func IsInternalServer(err error) bool
- func IsNotFound(err error) bool
- func IsServiceUnavailable(err error) bool
- func IsUnauthorized(err error) bool
- func Reason(err error) string
- func Unwrap(err error) error
- type Error
- func BadRequest(service, reason, message string) *Error
- func Conflict(service, reason, message string) *Error
- func ErrorFmt(code codes.Code, domain, reason, format string, a ...interface{}) *Error
- func Forbidden(service, reason, message string) *Error
- func FromError(err error) *Error
- func InternalServer(service, reason, message string) *Error
- func New(code codes.Code, domain, reason, message string) *Error
- func NewFmt(code codes.Code, domain, reason, format string, a ...interface{}) *Error
- func NotFound(service, reason, message string) *Error
- func ServiceUnavailable(service, reason, message string) *Error
- func Unauthorized(service, reason, message string) *Error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶
As 在err链中找到与target匹配的第一个错误,如果匹配则将target设置为该错误值并返回true.
该链由err本身组成,其后是通过重复调用Unwrap获得的错误序列.
如果错误的具体值可分配给target指向的值,或者错误具有方法{As(interface{})bool}使得As(target)返回true,则错误与目标匹配。在后一种情况下,As方法负责设置目标. As 如果target不是实现错误的类型或任何接口类型的非nil指针将panic,如果err为nil,则返回false.
func Is ¶
Is 报告err链中的任何错误是否与target匹配.
该链由err本身组成,其后是通过重复调用Unwrap获得的错误序列. 如果错误等于target,或者它实现了{Is(error))bool}的方法使得Is(target)返回true,则认为该错误与该目标匹配 An error is considered to match a target if it is equal to that target or if it implements a method Is(error) bool such that Is(target) returns true.
func IsInternalServer ¶
IsInternalServer 确定err是否是指示InternalServer的错误,它支持包装错误.
func IsServiceUnavailable ¶
IsServiceUnavailable 确定err是否是指示ServiceUnavailable的错误,它支持包装错误.
func IsUnauthorized ¶
IsUnauthorized 确定err是否是表示Unauthorized的错误,它支持包装错误.
Types ¶
type Error ¶
type Error struct { Domain string `json:"domain"` Reason string `json:"reason"` Metadata map[string]string `json:"metadata"` // contains filtered or unexported fields }
Error 包含来自服务器的错误响应. 有关更多详细信息,请参见https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto.
func BadRequest ¶
BadRequest 映射到400响应的新BadRequest错误.
func InternalServer ¶
InternalServer 映射到500响应的新InternalServer错误.
func ServiceUnavailable ¶
ServiceUnavailable 映射到HTTP 503响应的新ServiceUnavailable错误.
func Unauthorized ¶
Unauthorized 映射到401响应的新的Unauthorized的错误.