crpc

package
v0.0.0-...-6ea4ef9 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PROTOCOL_NAME           = "crpc" //中信银行私有 rpc 协议
	ProtocolFirstByte  byte = 0x1A
	ProtocolSecondByte byte = 0x19

	DefaultExpiration      = 15 * time.Second
	DefaultCleanupInterval = 60 * time.Second

	HeaderBeginLen int = 6

	RequestHeaderLen          int = 102 // protocol header fields length
	RequestHeartBeatHeaderLen int = 28  // heartbeat header length
	RequestTagStartIndex      int = 103
	RequestHeaderLenBeforeTag     = RequestTagStartIndex - HeaderBeginLen - 2

	ResponseTagStartIndex      int = 79
	ResponseHeaderLenBeforeTag     = ResponseTagStartIndex - HeaderBeginLen - 2

	HeartBeatRequestHeaderLen                     int = 22
	HeartBeatHeaderLen                                = HeartBeatRequestHeaderLen - 2
	SOFARPC_ROUTER_RULE_METADATA_CRPC_TARGET_HOST     = "crpc_target_host"
	SOFARPC_ROUTER_RULE_METADATA_CRPC_TARGET_ZONE     = "crpc_target_zone"
	EGRESS                                            = "egress"
	INGRESS                                           = "ingress"

	VarProxyTryTimeout    string = "proxy_try_timeout"
	VarProxyGlobalTimeout string = "proxy_global_timeout"
	VarProxyHijackStatus  string = "proxy_hijack_status"
	VarProxyGzipSwitch    string = "proxy_gzip_switch"

	SERVICE_NAME_KEY        = "serviceName"
	SERVICE_VERSION_KEY     = "serviceVersion"
	GROUP_ID_KEY            = "groupId"
	SERVICE_METHOD_NAME_KEY = "methodName"
	TARGET_APP_NAME_KEY     = "destinationAppName"
	TRACE_ID_KEY            = "traceId"
	SPAN_ID_KEY             = "spanId"
	PARENT_SPAN_ID_KEY      = "parentSpanId"
	SAMPLED_KEY             = "sampled"
	FLAGS_KEY               = "flags"
	TRAN_NUM                = "tranNum"

	CRPC_SUCCESS            = "CRPC000"
	CRPC_RPC_REQUEST_ERROR  = "CRPC001"
	CRPC_RPC_RESPONSE_ERROR = "CRPC002"
	CRPC_TIMEOUT            = "CRPC003"
	CRPC_ROUTER_ERROR       = "CRPC004"
	CRPC_ERROR              = "CRPC005"

	MRPC_LIMIT_ERROR      = "MRPC001"
	MRPC_CIRCUIT_ERROR    = "MRPC002"
	MRPC_AUTH_ERROR       = "MRPC003"
	MRPC_DOWNGROUD_ERROR  = "MRPC004"
	MRPC_ROUTE_ERROR      = "MRPC005"
	MRPC_FAULT_RULE_ERROR = "MRPC006"
	MRPC_UNKNOWN_ERROR    = "MRPC009"
	//非服务治理相关的响应码
	MRPC_REQUEST_ERROR_CRPC001  = "MRPC101"
	MRPC_RESPONSE_ERROR_CRPC002 = "MRPC102"
	MRPC_TIMEOUT_CRPC003        = "MRPC103"

	AuthHiJackCode          = 403
	RouteHiJackCode         = 404
	CircuitBreakHiJackCode  = 418
	LimitExceededHiJackCode = 429
	FaultInjectHiJackCode   = 520
	DownGradeHiJackCode     = 509

	StatusOK                  = 200
	StatusGatewayTimeout      = 504
	StatusBadRequest          = 400
	StatusInternalServerError = 500

	GOVERN_TEST_TRAFFIC_KEY     = "X-Govern-Test-Traffic"
	GOVERN_SERVICE_KEY          = "X-Govern-Service"
	GOVERN_SERVICE_TYPE_KEY     = "X-Govern-Service-Type"
	GOVERN_METHOD_KEY           = "X-Govern-Method"
	GOVERN_TIMEOUT_KEY          = "X-Govern-Timeout"
	GOVERN_SOURCE_APP_KEY       = "X-Govern-Source-App"
	GOVERN_SOURCE_IP_KEY        = "X-Govern-Source-Ip"
	GOVERN_TARGET_APP_KEY       = "X-Govern-Target-App"
	GOVERN_RESP_CODE_KEY        = "X-Govern-Resp-Code"
	GOVERN_HIJACK_CODE_KEY      = "X-Govern-HiJack-Code"
	GOVERN_REQUEST_ID           = "X-Request-Id"
	GOVERN_TRACE_ID             = "X-B3-TraceId"
	GOVERN_TRACE_SPAN_ID        = "X-B3-SpanId"
	GOVERN_TRACE_PARENT_SPAN_ID = "X-B3-ParentSpanId"
	GOVERN_TRACE_SAMPLED        = "X-B3-Sampled"
	GOVERN_TRACE_flags          = "X-B3-Flags"

	CRPC_TRACER_HEADER_TARGET_DATACENTER  = "crpc_target_datacenter"
	CRPC_TRACER_HEADER_SOURCE_ZONE        = "crpc_source_zone"
	CRPC_TRACER_HEADER_SOURCE_DATACENTER  = "crpc_source_datacenter"
	CRPC_TRACER_HEADER_RESPONSE_CRPC_CODE = "response_rpc_code"
	CRPC_TRACER_HEADER_RESPONSE_BIZ_CODE  = "response_biz_code"
)

Variables

This section is empty.

Functions

func GetGovernValue

func GetGovernValue(context context.Context, headers proxy.Header, key string) (string, bool)

func MappingCrpcCode2HttpCode

func MappingCrpcCode2HttpCode(response *Response) (int, error)

func MappingHttpCode2CrpcCode

func MappingHttpCode2CrpcCode(httpStatusCode uint32) string

func NewCrpcProtocol

func NewCrpcProtocol() proxy.Protocol

func SetRequestHeaderValue

func SetRequestHeaderValue(request *Request)

Types

type Request

type Request struct {
	RequestHeader

	Data proxy.Buffer // wrapper of raw data
	Body proxy.Buffer // wrapper of raw body

	ContentChanged bool // indicate that content changed
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(requestId string, headers proxy.Header, data proxy.Buffer) *Request

func (*Request) CommandId

func (r *Request) CommandId() uint64

func (*Request) GetData

func (r *Request) GetData() proxy.Buffer

func (*Request) GetHeader

func (r *Request) GetHeader() proxy.Header

func (*Request) GetRequestId

func (r *Request) GetRequestId() uint64

func (*Request) GetTimeout

func (r *Request) GetTimeout() uint32

func (*Request) IsHeartbeat

func (r *Request) IsHeartbeat() bool

func (*Request) IsHeartbeatFrame

func (r *Request) IsHeartbeatFrame() bool

func (*Request) IsOneWay

func (r *Request) IsOneWay() bool

func (*Request) SetCommandId

func (r *Request) SetCommandId(id uint64)

func (*Request) SetData

func (r *Request) SetData(data proxy.Buffer)

func (*Request) SetRequestId

func (r *Request) SetRequestId(id uint64)

type RequestHeader

type RequestHeader struct {
	MagicNum         []byte //2 byte
	RequestLen       uint32 //4 byte
	HeaderLen        uint16 //2 byte
	Version          byte   //1 byte
	HeaderProperties []byte //3 byte
	Heartbeat        bool
	OneWay           bool
	RequestId        string //16 byte
	Timeout          uint32 //4 byte
	SourceApp        string //4 byte
	TranNum          string //36 byte
	ApplySysTime     string //26 byte
	CallApp          string //4 byte
	TagCnt           byte   //2 byte
	proxy.CommonHeader
}

func (*RequestHeader) Clone

func (h *RequestHeader) Clone() proxy.Header

type Response

type Response struct {
	ResponseHeader

	Data proxy.Buffer // wrapper of raw tags
	Body proxy.Buffer // wrapper of raw body

	ContentChanged bool
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse(requestId string, statusCode string, headers proxy.Header, data proxy.Buffer) *Response

func (*Response) CommandId

func (r *Response) CommandId() uint64

func (*Response) GetData

func (r *Response) GetData() proxy.Buffer

func (*Response) GetHeader

func (r *Response) GetHeader() proxy.Header

func (*Response) GetRequestId

func (r *Response) GetRequestId() uint64

~ XRespFrame

func (*Response) GetStatus

func (r *Response) GetStatus() uint32

func (*Response) GetStatusCode

func (r *Response) GetStatusCode() uint32

func (*Response) IsHeartbeat

func (r *Response) IsHeartbeat() bool

func (*Response) IsHeartbeatFrame

func (r *Response) IsHeartbeatFrame() bool

func (*Response) SetCommandId

func (r *Response) SetCommandId(id uint64)

func (*Response) SetData

func (r *Response) SetData(data proxy.Buffer)

func (*Response) SetRequestId

func (r *Response) SetRequestId(id uint64)

type ResponseHeader

type ResponseHeader struct {
	MagicNum         []byte //2 byte
	ResponseLen      uint32 //4 byte
	HeaderLen        uint16 //2 byte
	Version          byte   //1 byte
	HeaderProperties []byte //3 byte
	Heartbeat        bool
	RequestId        string //16 byte
	TranNum          string //36 byte
	RpcRespCode      string //7 byte
	AppRespCode      string //7 byte
	TagCnt           byte   //1 byte
	proxy.CommonHeader
}

func (*ResponseHeader) Clone

func (h *ResponseHeader) Clone() proxy.Header

type Time

type Time int64

A Time represents a time as the number of 100's of nanoseconds since 15 Oct 1582.

func GetTime

func GetTime() (Time, uint16, error)

GetTime returns the current Time (100s of nanoseconds since 15 Oct 1582) and clock sequence as well as adjusting the clock sequence as needed. An error is returned if the current time cannot be determined.

type UUID

type UUID [16]byte

A UUID is a 128 bit (16 byte) Universal Unique IDentifier as defined in RFC 4122.

var Nil UUID // empty UUID, all zeros

func FromBytes

func FromBytes(b []byte) (uuid UUID, err error)

FromBytes creates a new UUID from a byte slice. Returns an error if the slice does not have a length of 16. The bytes are copied from the slice.

func NewUUID

func NewUUID() (UUID, error)

func Parse

func Parse(s string) (UUID, error)

Parse decodes s into a UUID or returns an error. Both the standard UUID forms of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx are decoded as well as the Microsoft encoding {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} and the raw hex encoding: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.

func (UUID) String

func (uuid UUID) String() string

String returns the string form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx , or "" if uuid is invalid.

func (*UUID) UnmarshalBinary

func (uuid *UUID) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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