micro

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

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
	ErrUnavailableForLegalReasons   codes.Code = 451 // RFC 7725, 3

	//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
	ErrServiceUnavailable            codes.Code = 503 // RFC 7231, 6.6.4
	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 object is unavaiable/disabled
	ErrObjectUnavailable codes.Code = 1001
)

Variables

View Source
var (
	//ErrUnknown 无法识别的错误
	ErrUnknown = errors.New("ErrUnknown")
	//ErrBadRequest 客戶端請求參數錯誤
	ErrBadRequest = errors.New("ErrBadRequest")
	//ErrInvalidArgument 無效變數,服務器內部調用,參數不合法
	ErrInvalidArgument = errors.New("ErrInvalidArgument")
	//ErrUnauthorized 未驗證登錄操作
	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 IsError

func IsError(err error) bool

IsError 檢測是否自定義錯誤

func LogThrow

func LogThrow(ctx context.Context, l log.Level, message string) string

LogThrow 记录内部错误,返回错误编码

func LogThrowf

func LogThrowf(ctx context.Context, l log.Level, format string, args ...interface{}) string

LogThrowf 记录内部错误,返回错误编码

func NewContext

func NewContext() context.Context

NewContext return root context of micro

func Throw

func Throw(ctx context.Context, err error, message string) error

Throw 創建一個可帶參數和基礎錯誤類型的錯誤對象,支持go2的errors設計規範 https://github.com/golang/go/wiki/ErrorValueFAQ

func Throwf

func Throwf(ctx context.Context, err error, format string, args ...interface{}) error

Throwf 創建一個可帶參數和基礎錯誤類型的錯誤對象,支持go2的errors設計規範

func WithContext

func WithContext(ctx context.Context, rctx RequestContext) context.Context

WithContext returns a new Context with RequestConext.

func WithValues

func WithValues(parent context.Context, values map[string]string) context.Context

WithValues returns a copy of parent in which the value associated with values

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error 自定義錯誤對象

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap 實現errors.Wrapper

type HTTPClient

type HTTPClient struct {
	// contains filtered or unexported fields
}

HTTPClient Http请求客户端, 可全局共享一个对象实例

func NewHTTPClient

func NewHTTPClient(options ...HTTPClientOption) *HTTPClient

NewHTTPClient 创建HTTPClient对象

func (*HTTPClient) Do

func (c *HTTPClient) Do(ctx context.Context, method, url string, data string, header map[string]string) ([]byte, int, error)

Do 执行请求

type HTTPClientOption

type HTTPClientOption func(c *HTTPClient)

HTTPClientOption HTTP请求参数

type RequestContext

type RequestContext struct {
	RequestID   string
	RequsetTime time.Time

	AcceptLanguage string
}

RequestContext a request-scope context

func FromContext

func FromContext(ctx context.Context) (RequestContext, bool)

FromContext extracts the RequestContext from ctx, if present.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL