Documentation ¶
Index ¶
- Constants
- func GetGovernValue(context context.Context, headers proxy.Header, key string) (string, bool)
- func MappingCrpcCode2HttpCode(response *Response) (int, error)
- func MappingHttpCode2CrpcCode(httpStatusCode uint32) string
- func NewCrpcProtocol() proxy.Protocol
- func SetRequestHeaderValue(request *Request)
- type Request
- func (r *Request) CommandId() uint64
- func (r *Request) GetData() proxy.Buffer
- func (r *Request) GetHeader() proxy.Header
- func (r *Request) GetRequestId() uint64
- func (r *Request) GetTimeout() uint32
- func (r *Request) IsHeartbeat() bool
- func (r *Request) IsHeartbeatFrame() bool
- func (r *Request) IsOneWay() bool
- func (r *Request) SetCommandId(id uint64)
- func (r *Request) SetData(data proxy.Buffer)
- func (r *Request) SetRequestId(id uint64)
- type RequestHeader
- type Response
- func (r *Response) CommandId() uint64
- func (r *Response) GetData() proxy.Buffer
- func (r *Response) GetHeader() proxy.Header
- func (r *Response) GetRequestId() uint64
- func (r *Response) GetStatus() uint32
- func (r *Response) GetStatusCode() uint32
- func (r *Response) IsHeartbeat() bool
- func (r *Response) IsHeartbeatFrame() bool
- func (r *Response) SetCommandId(id uint64)
- func (r *Response) SetData(data proxy.Buffer)
- func (r *Response) SetRequestId(id uint64)
- type ResponseHeader
- type Time
- type UUID
Constants ¶
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 NewCrpcProtocol ¶
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 (*Request) GetRequestId ¶
func (*Request) GetTimeout ¶
func (*Request) IsHeartbeat ¶
func (*Request) IsHeartbeatFrame ¶
func (*Request) SetCommandId ¶
func (*Request) SetRequestId ¶
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 (*Response) GetStatusCode ¶
func (*Response) IsHeartbeat ¶
func (*Response) IsHeartbeatFrame ¶
func (*Response) SetCommandId ¶
func (*Response) SetRequestId ¶
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.
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 ¶
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 Parse ¶
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 ¶
String returns the string form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx , or "" if uuid is invalid.
func (*UUID) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler.