Documentation
¶
Index ¶
- Constants
- Variables
- func CancelContext()
- func IsError(err error) bool
- func LogThrow(ctx context.Context, l log.Level, message string) string
- func LogThrowf(ctx context.Context, l log.Level, format string, args ...interface{}) string
- func NewContext() context.Context
- func Throw(ctx context.Context, err error, message string) error
- func Throwf(ctx context.Context, err error, format string, args ...interface{}) error
- func WithContext(ctx context.Context, rctx RequestContext) context.Context
- func WithValues(parent context.Context, values map[string]string) context.Context
- type Error
- type HTTPClient
- type HTTPClientOption
- type RequestContext
Constants ¶
View Source
const ( // ErrBadRequest codes.Code = 400 // RFC 7231, 6.5.1 //ErrUnauthorized codes.Code = 401 // RFC 7235, 3.1 ErrPaymentRequired codes.Code = 402 // RFC 7231, 6.5.2 //ErrForbidden codes.Code = 403 // RFC 7231, 6.5.3 //ErrNotFound codes.Code = 404 // RFC 7231, 6.5.4 ErrMethodNotAllowed codes.Code = 405 // RFC 7231, 6.5.5 ErrNotAcceptable codes.Code = 406 // RFC 7231, 6.5.6 ErrProxyAuthRequired codes.Code = 407 // RFC 7235, 3.2 ErrRequestTimeout codes.Code = 408 // RFC 7231, 6.5.7 ErrConflict codes.Code = 409 // RFC 7231, 6.5.8 ErrGone codes.Code = 410 // RFC 7231, 6.5.9 ErrLengthRequired codes.Code = 411 // RFC 7231, 6.5.10 ErrPreconditionFailed codes.Code = 412 // RFC 7232, 4.2 ErrRequestEntityTooLarge codes.Code = 413 // RFC 7231, 6.5.11 ErrRequestURITooLong codes.Code = 414 // RFC 7231, 6.5.12 ErrUnsupportedMediaType codes.Code = 415 // RFC 7231, 6.5.13 ErrRequestedRangeNotSatisfiable codes.Code = 416 // RFC 7233, 4.4 ErrExpectationFailed codes.Code = 417 // RFC 7231, 6.5.14 ErrTeapot codes.Code = 418 // RFC 7168, 2.3.3 ErrUnprocessableEntity codes.Code = 422 // RFC 4918, 11.2 ErrLocked codes.Code = 423 // RFC 4918, 11.3 ErrFailedDependency codes.Code = 424 // RFC 4918, 11.4 ErrUpgradeRequired codes.Code = 426 // RFC 7231, 6.5.15 ErrPreconditionRequired codes.Code = 428 // RFC 6585, 3 ErrTooManyRequests codes.Code = 429 // RFC 6585, 4 ErrRequestHeaderFieldsTooLarge codes.Code = 431 // RFC 6585, 5 //ErrInternalServerError codes.Code = 500 // RFC 7231, 6.6.1 ErrNotImplemented codes.Code = 501 // RFC 7231, 6.6.2 ErrBadGateway codes.Code = 502 // RFC 7231, 6.6.3 ErrGatewayTimeout codes.Code = 504 // RFC 7231, 6.6.5 ErrHTTPVersionNotSupported codes.Code = 505 // RFC 7231, 6.6.6 ErrVariantAlsoNegotiates codes.Code = 506 // RFC 2295, 8.1 ErrInsufficientStorage codes.Code = 507 // RFC 4918, 11.5 ErrLoopDetected codes.Code = 508 // RFC 5842, 7.2 ErrNotExtended codes.Code = 510 // RFC 2774, 7 ErrNetworkAuthenticationRequired codes.Code = 511 // RFC 6585, 6 )
View Source
const ( //ErrPasswordMismatch login and password are mismatched ErrPasswordMismatch codes.Code = 1000 ErrObjectUnavailable codes.Code = 1001 )
Variables ¶
View Source
var ( //ErrUnknown 无法识别的错误 ErrUnknown = errors.New("ErrUnknown") //ErrBadRequest 客戶端請求參數錯誤 ErrBadRequest = errors.New("ErrBadRequest") //ErrInvalidArgument 無效變數,服務器內部調用,參數不合法 ErrInvalidArgument = errors.New("ErrInvalidArgument") ErrUnauthorized = errors.New("ErrUnauthorized") //ErrForbidden 服務端未授權操作 ErrForbidden = errors.New("ErrForbidden") //ErrMySQL MySQL操作错误 ErrMySQL = errors.New("ErrMySQL") //ErrInternalServerError 服务器内部通用错误 ErrInternalServerError = errors.New("ErrInternalServerError") //ErrNotFound 资源不存在 ErrNotFound = errors.New("ErrNotFound") )
View Source
var DefaultHTTPClient = NewHTTPClient()
DefaultHTTPClient 默认HTTPClient实例
View Source
var ( //ThrowLogger 内部错误日志,用于串联内外错误信息 ThrowLogger = log.NewLogger("throw") )
Functions ¶
func CancelContext ¶
func CancelContext()
CancelContext cancel all contexts derived from micro context
func Throw ¶
Throw 創建一個可帶參數和基礎錯誤類型的錯誤對象,支持go2的errors設計規範 https://github.com/golang/go/wiki/ErrorValueFAQ
func WithContext ¶
func WithContext(ctx context.Context, rctx RequestContext) context.Context
WithContext returns a new Context with RequestConext.
Types ¶
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient Http请求客户端, 可全局共享一个对象实例
func NewHTTPClient ¶
func NewHTTPClient(options ...HTTPClientOption) *HTTPClient
NewHTTPClient 创建HTTPClient对象
type RequestContext ¶
RequestContext a request-scope context
func FromContext ¶
func FromContext(ctx context.Context) (RequestContext, bool)
FromContext extracts the RequestContext from ctx, if present.
Click to show internal directories.
Click to hide internal directories.