Documentation ¶
Overview ¶
Package protocol is a generated protocol buffer package.
It is generated from these files:
iceberg.proto
It has these top-level messages:
Proto
Index ¶
- Constants
- Variables
- func Extract(stream []byte) (pack []byte, err error)
- func FetchBizID(printableBizID string) string
- func Pack(format RestfulFormat, data interface{}) ([]byte, error)
- func PrintableBizID(bizid string) string
- func Unpack(fromat RestfulFormat, in []byte, out interface{}) error
- type ErrInfo
- type Proto
- func (pro *Proto) AsString() string
- func (*Proto) Descriptor() ([]byte, []int)
- func (pro *Proto) FillErrInfo(code int, err error)
- func (pro *Proto) ForeachKey(handler func(key, val string) error) error
- func (m *Proto) GetBizid() string
- func (m *Proto) GetBody() []byte
- func (m *Proto) GetErr() []byte
- func (m *Proto) GetFormat() RestfulFormat
- func (m *Proto) GetMethod() RestfulMethod
- func (m *Proto) GetRequestID() int64
- func (m *Proto) GetServeMethod() string
- func (m *Proto) GetServeURI() string
- func (m *Proto) GetTraceMap() map[string]string
- func (pro *Proto) PrintableBizID() string
- func (*Proto) ProtoMessage()
- func (m *Proto) Reset()
- func (pro *Proto) Serialize() ([]byte, error)
- func (pro *Proto) Set(key, val string)
- func (pro *Proto) Shadow() Proto
- func (m *Proto) String() string
- func (pro *Proto) UnSerialize(srcBuf []byte) error
- type Raw
- type RestfulFormat
- type RestfulMethod
Constants ¶
View Source
const ( OK = iota BadProtocol ParseRequestFail ParseResponseFail RequestFail NotSupportMethod NotFoundInterface SvrReturnInvalidData SvrInternalFail )
定义响应类型
View Source
const HeaderLength = 4 // 包的长度,单位bytes
HeaderLength 包头长度
Variables ¶
View Source
var RestfulFormat_name = map[int32]string{
0: "FORMATNULL",
1: "XML",
2: "JSON",
3: "PROTOBUF",
4: "RAWQUERY",
}
View Source
var RestfulFormat_value = map[string]int32{
"FORMATNULL": 0,
"XML": 1,
"JSON": 2,
"PROTOBUF": 3,
"RAWQUERY": 4,
}
View Source
var RestfulMethod_name = map[int32]string{
0: "METHODNULL",
1: "POST",
2: "PUT",
3: "GET",
4: "DELETE",
}
View Source
var RestfulMethod_value = map[string]int32{
"METHODNULL": 0,
"POST": 1,
"PUT": 2,
"GET": 3,
"DELETE": 4,
}
Functions ¶
func Unpack ¶
func Unpack(fromat RestfulFormat, in []byte, out interface{}) error
Unpack 对请求数据进行反序列化
Types ¶
type Proto ¶
type Proto struct { // 全局唯一ID,用于日志追踪 Bizid string `protobuf:"bytes,1,opt,name=Bizid" json:"Bizid,omitempty" xml:"Bizid,omitempty"` // 集成zipkin trace功能 TraceMap map[string]string `` /* 161-byte string literal not displayed */ // 递增请求ID,服务内唯一 RequestID int64 `protobuf:"varint,3,opt,name=RequestID" json:"RequestID,omitempty" xml:"RequestID,omitempty"` // 路由 Path 如:/services/v1/orderpay/order ServeURI string `protobuf:"bytes,4,opt,name=ServeURI" json:"ServeURI,omitempty" xml:"ServeURI,omitempty"` // 数据编码格式 Format RestfulFormat `protobuf:"varint,5,opt,name=Format,enum=protocol.RestfulFormat" json:"Format,omitempty" xml:"Format,omitempty"` // 服务方法 如:CreateOrderWithPay ServeMethod string `protobuf:"bytes,6,opt,name=ServeMethod" json:"ServeMethod,omitempty" xml:"ServeMethod,omitempty"` // HTTP Method Method RestfulMethod `protobuf:"varint,7,opt,name=Method,enum=protocol.RestfulMethod" json:"Method,omitempty" xml:"Method,omitempty"` // 请求/响应信息 Body []byte `protobuf:"bytes,8,opt,name=Body,proto3" json:"Body,omitempty" xml:"Body,omitempty"` // 响应错误信息,Body 和 Err 互斥 Err []byte `protobuf:"bytes,9,opt,name=Err,proto3" json:"Err,omitempty" xml:"Err,omitempty"` }
func (*Proto) AsString ¶
AsString 将结构体序列化后的结果,转成可读的字符串 其实就是剥离包头表示长度的字节,因为序列化是json操作。所以剥离包头的长度后就是可读的内容了
func (*Proto) Descriptor ¶
func (*Proto) ForeachKey ¶
ForeachKey 实现opentracing TextMapReader接口,用于opentacing Extract
func (*Proto) GetFormat ¶
func (m *Proto) GetFormat() RestfulFormat
func (*Proto) GetMethod ¶
func (m *Proto) GetMethod() RestfulMethod
func (*Proto) GetRequestID ¶
func (*Proto) GetServeMethod ¶
func (*Proto) GetServeURI ¶
func (*Proto) GetTraceMap ¶
func (*Proto) PrintableBizID ¶
PrintableBizID 输出请求的bizid用于在log输出中作为请求的唯一标识
func (*Proto) ProtoMessage ¶
func (*Proto) ProtoMessage()
func (*Proto) Shadow ¶
Shadow 生成该结果的一个影子。所谓影子是指生产的影子结构和该结果本身除了 body, err 两个字段内容为空以外,其他的字段都一样。 影子结构的用途是在有限的复制请求,作为响应的基础。这样就能保证请求和响应的 bizid, requestID是一致的。不容易在写代码的复制,粘贴过程出现失误。
func (*Proto) UnSerialize ¶
UnSerialize 从一段连续的字节块中解析Proto结构的内容 块头的4byte表示字节块的长度(该长度包含这4byte在内)
type RestfulFormat ¶
type RestfulFormat int32
BODY 体格式
const ( RestfulFormat_FORMATNULL RestfulFormat = 0 RestfulFormat_XML RestfulFormat = 1 RestfulFormat_JSON RestfulFormat = 2 RestfulFormat_PROTOBUF RestfulFormat = 3 RestfulFormat_RAWQUERY RestfulFormat = 4 )
func (RestfulFormat) EnumDescriptor ¶
func (RestfulFormat) EnumDescriptor() ([]byte, []int)
func (RestfulFormat) String ¶
func (x RestfulFormat) String() string
type RestfulMethod ¶
type RestfulMethod int32
const ( RestfulMethod_METHODNULL RestfulMethod = 0 RestfulMethod_POST RestfulMethod = 1 RestfulMethod_PUT RestfulMethod = 2 RestfulMethod_GET RestfulMethod = 3 RestfulMethod_DELETE RestfulMethod = 4 )
func (RestfulMethod) EnumDescriptor ¶
func (RestfulMethod) EnumDescriptor() ([]byte, []int)
func (RestfulMethod) String ¶
func (x RestfulMethod) String() string
Click to show internal directories.
Click to hide internal directories.