Documentation ¶
Overview ¶
Package context 提供每次 RAL 请求的上下文对象,主要用来输出日志。
Index ¶
Constants ¶
View Source
const ( ErrnoHTTPEmptyBody = "700" ErrnoHTTPAwaitingHeadersExceeded = "701" ErrnoHTTPIOTimeout = "702" ErrnoUnKnown = "999" )
Variables ¶
View Source
var Err2ErrorHandlers = []Err2ErrorHandler{ func(protocol string, errMsg string) (errno string, dealSucc bool) { if protocol != "http" { return } if strings.HasSuffix(errMsg, "with Body length 0") { return ErrnoHTTPEmptyBody, true } return }, func(protocol string, errMsg string) (errno string, dealSucc bool) { if protocol != "http" { return } if strings.HasSuffix(errMsg, "net/http: request canceled (Client.Timeout exceeded while awaiting headers)") { return ErrnoHTTPAwaitingHeadersExceeded, true } return }, func(protocol string, errMsg string) (errno string, dealSucc bool) { if protocol != "http" { return } if strings.HasSuffix(errMsg, "i/o timeout") { return ErrnoHTTPEmptyBody, true } return }, }
Err2ErrorHandlers 错误转换处理者
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { ReqContext RequestContext Caller string ServiceName string ReqLen int64 RspLen int64 Method string TraceID interface{} Protocol string BalanceName string PackStatis *StatisItem MaxTry int // contains filtered or unexported fields }
Context 用作日志记录
func (*Context) TimeStatisStart ¶
TimeStatisStart 开始一个统计项
func (*Context) TimeStatisStop ¶
TimeStatisStop 停止一个统计项
type Err2ErrorHandler ¶
Err2ErrorHandler 错误转换为错误码 protocol 请求协议 当前有 http, nshead, pbrpc, mysql, redis
type InvokeRecord ¶
type InvokeRecord struct { // RspCode 请求的响应码 // http 代表 http status code,200 为正常,700+是自定义的错误码,表示发送请求时发生了error // nshead 等有自己的规则,不统一描述 RspCode int // Path 请求的路径 // http 相对path, 形如: /foo/bar Path string // IPPort ip和端口号 IPPort string // Host 域名,可能和IPPort 一致 Host string // 一次请求最多一条错误日志 Error error // contains filtered or unexported fields }
InvokeRecord 访问日志,因为重试可能有多条
func (*InvokeRecord) GetTimePoint ¶
func (invokeRecord *InvokeRecord) GetTimePoint(topic string) string
GetTimePoint 得到一个时间点 毫秒
func (*InvokeRecord) GetTimeStatis ¶
func (invokeRecord *InvokeRecord) GetTimeStatis(topic string) string
GetTimeStatis 获取一个统计项
func (*InvokeRecord) RecordTimePoint ¶
func (invokeRecord *InvokeRecord) RecordTimePoint(topic string)
RecordTimePoint 打下一个时间点
type RequestContext ¶
RequestContext Web请求的上下文
type StatisItem ¶
StatisItem 时间统计项
Click to show internal directories.
Click to hide internal directories.