protocol

package
v0.0.0-...-fa9b265 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2017 License: GPL-2.0 Imports: 7 Imported by: 0

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

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 Extract

func Extract(stream []byte) (pack []byte, err error)

Extract extract mediaType and pack

func FetchBizID

func FetchBizID(printableBizID string) string

FetchBizID fetch bizID

func Pack

func Pack(format RestfulFormat, data interface{}) ([]byte, error)

Pack 对请求响应数据进行序列化

func PrintableBizID

func PrintableBizID(bizid string) string

PrintableBizID Printable bizID

func Unpack

func Unpack(fromat RestfulFormat, in []byte, out interface{}) error

Unpack 对请求数据进行反序列化

Types

type ErrInfo

type ErrInfo struct {
	ErrCode int    `json:"err_code"`
	ErrInfo string `json:"err_msg"`
}

ErrInfo 服务之间通用的错误信息结构

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

func (pro *Proto) AsString() string

AsString 将结构体序列化后的结果,转成可读的字符串 其实就是剥离包头表示长度的字节,因为序列化是json操作。所以剥离包头的长度后就是可读的内容了

func (*Proto) Descriptor

func (*Proto) Descriptor() ([]byte, []int)

func (*Proto) FillErrInfo

func (pro *Proto) FillErrInfo(code int, err error)

FillErrInfo 填充错误信息

func (*Proto) ForeachKey

func (pro *Proto) ForeachKey(handler func(key, val string) error) error

ForeachKey 实现opentracing TextMapReader接口,用于opentacing Extract

func (*Proto) GetBizid

func (m *Proto) GetBizid() string

func (*Proto) GetBody

func (m *Proto) GetBody() []byte

func (*Proto) GetErr

func (m *Proto) GetErr() []byte

func (*Proto) GetFormat

func (m *Proto) GetFormat() RestfulFormat

func (*Proto) GetMethod

func (m *Proto) GetMethod() RestfulMethod

func (*Proto) GetRequestID

func (m *Proto) GetRequestID() int64

func (*Proto) GetServeMethod

func (m *Proto) GetServeMethod() string

func (*Proto) GetServeURI

func (m *Proto) GetServeURI() string

func (*Proto) GetTraceMap

func (m *Proto) GetTraceMap() map[string]string

func (*Proto) PrintableBizID

func (pro *Proto) PrintableBizID() string

PrintableBizID 输出请求的bizid用于在log输出中作为请求的唯一标识

func (*Proto) ProtoMessage

func (*Proto) ProtoMessage()

func (*Proto) Reset

func (m *Proto) Reset()

func (*Proto) Serialize

func (pro *Proto) Serialize() ([]byte, error)

Serialize 将Proto结构的内容写入一段连续的字节块,并在块头用4byte表示字节块的长度。 该长度包含这4byte在内

func (*Proto) Set

func (pro *Proto) Set(key, val string)

Set 实现opentracing TextMapWriter接口,用于opentracing Inject

func (*Proto) Shadow

func (pro *Proto) Shadow() Proto

Shadow 生成该结果的一个影子。所谓影子是指生产的影子结构和该结果本身除了 body, err 两个字段内容为空以外,其他的字段都一样。 影子结构的用途是在有限的复制请求,作为响应的基础。这样就能保证请求和响应的 bizid, requestID是一致的。不容易在写代码的复制,粘贴过程出现失误。

func (*Proto) String

func (m *Proto) String() string

func (*Proto) UnSerialize

func (pro *Proto) UnSerialize(srcBuf []byte) error

UnSerialize 从一段连续的字节块中解析Proto结构的内容 块头的4byte表示字节块的长度(该长度包含这4byte在内)

type Raw

type Raw interface {
	Get() []byte
	Set([]byte) error
}

Raw 处理原始报文

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

Jump to

Keyboard shortcuts

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