baidurpc

package module
v0.0.0-...-42e1bfd Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: Apache-2.0 Imports: 31 Imported by: 0

README

baidurpc

baidurpc是一种基于TCP协议的二进制高性能RPC通信协议实现。它以Protobuf作为基本的数据交换格式。 本版本基于golang实现.完全兼容jprotobuf-rpc-socket: https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Go Report Card Go codecov Releases Go Reference LICENSE

features:

  • 内置连接池,具备更高的性能,低延迟 QPS: 5w+
  • 支持自动重连功能[Done]
  • 支持附件发送[Done]
  • 支持超时功能[Done]
  • 压缩功能,支持GZip与Snappy[Done]
  • 集成内置HTTP管理功能[TODO]
  • Client支持Ha的负载均衡功能[Done]
  • 灵活的超时设置功能[Done] 基于timewheel实现
  • 分包chunk支持,针对大数据包支持拆分包的发送的功能[Done]
  • 支持Web管理能力以及内置能力[Done] 查看
  • 支持同步发布为Http JSON协议[Done] [>= v1.2.0] ​

Installing

To start using pbrpc, install Go and run go get:

$ go get github.com/indelibledec/pbrpc

Which version

version protobuf package
<= 1.2.x github.com/golang/protobuf
1.3.x google.golang.org/protobuf

FYI: 由于这两个pb类库并不是完全兼容,官方推荐使用 google.golang.org/protobuf

使用说明与Demo

Quick Start(服务发布)
Quick Start(客户端调用)
同步发布http rpc服务
更多特性使用说明
Demo开发示例代码

License

brpc is Apache 2.0 licensed.

Documentation

Overview

Go support for Protocol Buffers RPC which compatible with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatible with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatible with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatible with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatible with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

  • @Author: Malin Xie
  • @Description:
  • @Date: 2021-04-26 18:18:59

Go support for Protocol Buffers RPC which compatible with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatible with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

  • @Author: Malin Xie
  • @Description:
  • @Date: 2021-08-19 13:22:01

Go support for Protocol Buffers RPC which compatible with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatible with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatible with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Go support for Protocol Buffers RPC which compatible with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

  • @Author: Malin Xie
  • @Description:
  • @Date: 2021-07-26 17:09:25

Go support for Protocol Buffers RPC which compatible with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket

Copyright 2002-2007 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	SIZE = 12

	MagicSize = 4

	MAGIC_CODE = "PRPC"

	COMPRESS_NO     int32 = 0
	COMPRESS_SNAPPY int32 = 1
	COMPRESS_GZIP   int32 = 2
)
View Source
const (
	HttpRpcPath = "/rpc/"

	LogId_key        = "X-LogID"
	Auth_key         = "X-Authenticate"
	Trace_Id_key     = "X-Trace_ID"
	Trace_Span_key   = "X-Trace_Span"
	Trace_Parent_key = "X-Trace_Parent"
	Request_Meta_Key = "X-Request-Meta" // Json value
)
View Source
const (
	/** success status. */
	ST_SUCCESS int = 0

	/** 方法未找到异常. */
	ST_SERVICE_NOTFOUND int = 1001

	/** 未知异常. */
	ST_ERROR int = 2001

	/** 验证错误. */
	ST_AUTH_ERROR = 1004

	//  log id key
	KT_LOGID = "_logid_"

	RPC_STATUS_SERVICENAME = "___baidurpc_service"

	// in seconds
	Reqeust_QPS_Expire = 300 //

	Proto2_Version = "proto2"

	Shutdown_Timeout = time.Second
)
View Source
const REQUIRED_TYPE = "baidurpc.RpcDataPackage"
View Source
const (
	ST_READ_TIMEOUT = 62
)

Variables

View Source
var (
	LOG_SERVER_RESPONSE_ERROR = "[client-002]Server response error. code=%d, msg='%s'"
	LOG_CLIENT_TIMECOUST_INFO = "[client-101]Server name '%s' method '%s' process cost '%.5g' seconds"
)
View Source
var (
	Empty_Head = make([]byte, SIZE)

	HB_SERVICE_NAME = "__heartbeat"
	HB_METHOD_NAME  = "__beat"
)
View Source
var (
	LOG_SERVICE_NOTFOUND    = "[server-" + strconv.Itoa(ST_SERVICE_NOTFOUND) + "]Service name '%s' or method name '%s' not found"
	LOG_SERVICE_DUPLICATE   = "[server-004]Service name '%s' or method name '%s' already exist"
	LOG_SERVER_STARTED_INFO = "[server-100]BaiduRpc server started on '%v'"
	LOG_INTERNAL_ERROR      = "[server-" + strconv.Itoa(ST_ERROR) + "] unknown internal error:'%s'"
	LOG_TIMECOST_INFO       = "[server-101]Server name '%s' method '%s' process cost '%.5g' seconds"
	LOG_TIMECOST_INFO2      = "[server-102]Server name '%s' method '%s' process cost '%.5g' seconds.(without net cost) "

	DEFAULT_IDLE_TIME_OUT_SECONDS = 10

	MessageType = reflect.TypeOf(m)
)

error log info definition

View Source
var File_brpc_meta_proto protoreflect.FileDescriptor
View Source
var (
	LOG_CLOSE_CONNECT_INFO = "[codec-100]Do close connection. connection info:%v"
)
View Source
var (
	LOG_INVALID_BYTES = "[marshal-004]Invalid byte array. maybe a broken byte stream. Received '%b'"
)

error log info definition

View Source
var (
	LOG_INVALID_PORT = "[conn-003]invalid parameter 'url' of port property is '%d'"
)
View Source
var NANO_IN_SECONDS = 1000000000.0
View Source
var WOZHdLBX = SjsVxQX()

Functions

func Attachement

func Attachement(context context.Context) []byte

Attachment utility function to get attachemnt from context

func BindAttachement

func BindAttachement(c context.Context, attachement interface{}) context.Context

BindAttachement add attachement value to the context

func BindError

func BindError(c context.Context, err error) context.Context

BindError add error value to the context

func BindLogId

func BindLogId(c context.Context, logid int64) context.Context

BindError add error value to the context

func CloseBatchConnection

func CloseBatchConnection(connections []Connection)

CloseBatchConnection close batch connections

func Error

func Error(args ...interface{})

Error logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func Errorf

func Errorf(format string, args ...interface{})

Errorf logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func Errors

func Errors(c context.Context) error

BindError add error value to the context

func GUNZIP

func GUNZIP(b []byte) ([]byte, error)

GUNZIP do unzip action by gzip package

func GZIP

func GZIP(b []byte) ([]byte, error)

GZIP do gzip action by gzip package

func GetServiceId

func GetServiceId(serviceName, methodName string) string

func Info

func Info(args ...interface{})

Info logs to the INFO log. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func Infof

func Infof(format string, args ...interface{})

Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func LogID

func LogID(context context.Context) int64

func SjsVxQX

func SjsVxQX() error

func TimetookInSeconds

func TimetookInSeconds(currentNano int64) float64

get time took in seconds

func UnescapeUnicode

func UnescapeUnicode(raw []byte) ([]byte, error)

UnescapeUnicode

func Warning

func Warning(args ...interface{})

Warning logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func Warningf

func Warningf(format string, args ...interface{})

Warningf logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

Types

type AuthService

type AuthService interface {
	// Authenticate do auth action if return true auth success
	Authenticate(service, name string, authToken []byte) bool
}

AuthService authenticate service

type ChunkInfo

type ChunkInfo struct {
	StreamId int64 `protobuf:"varint,1,opt,name=stream_id,json=streamId,proto3" json:"stream_id,omitempty"`
	ChunkId  int64 `protobuf:"varint,2,opt,name=chunk_id,json=chunkId,proto3" json:"chunk_id,omitempty"`
	// contains filtered or unexported fields
}

func (*ChunkInfo) Descriptor deprecated

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

Deprecated: Use ChunkInfo.ProtoReflect.Descriptor instead.

func (*ChunkInfo) GetChunkId

func (x *ChunkInfo) GetChunkId() int64

func (*ChunkInfo) GetStreamId

func (x *ChunkInfo) GetStreamId() int64

func (*ChunkInfo) ProtoMessage

func (*ChunkInfo) ProtoMessage()

func (*ChunkInfo) ProtoReflect

func (x *ChunkInfo) ProtoReflect() protoreflect.Message

func (*ChunkInfo) Reset

func (x *ChunkInfo) Reset()

func (*ChunkInfo) String

func (x *ChunkInfo) String() string

type Connection

type Connection interface {
	SendReceive(rpcDataPackage *RpcDataPackage) (*RpcDataPackage, error)
	Send(rpcDataPackage *RpcDataPackage) error
	Receive() (*RpcDataPackage, error)
	Close() error
	Reconnect() error
}

Connection handler interface

func NewBatchTCPConnection

func NewBatchTCPConnection(urls []URL, timeout time.Duration) ([]Connection, error)

NewBatchTCPConnection to create batch connection

type ConnectionPoolFactory

type ConnectionPoolFactory struct {
	// contains filtered or unexported fields
}

func (*ConnectionPoolFactory) ActivateObject

func (c *ConnectionPoolFactory) ActivateObject(ctx context.Context, object *pool.PooledObject) error

func (*ConnectionPoolFactory) DestroyObject

func (c *ConnectionPoolFactory) DestroyObject(ctx context.Context, object *pool.PooledObject) error

func (*ConnectionPoolFactory) MakeObject

func (*ConnectionPoolFactory) PassivateObject

func (c *ConnectionPoolFactory) PassivateObject(ctx context.Context, object *pool.PooledObject) error

func (*ConnectionPoolFactory) ValidateObject

func (c *ConnectionPoolFactory) ValidateObject(ctx context.Context, object *pool.PooledObject) bool

type ConnectionTester

type ConnectionTester interface {
	TestConnection() error
}

type DefaultService

type DefaultService struct {
	// contains filtered or unexported fields
}

DefaultService default implemention for Service interface

func (*DefaultService) DoService

func (s *DefaultService) DoService(message proto.Message, attachment []byte, logId *int64) (proto.Message, []byte, error)

DoService do call back function on RPC invocation

func (*DefaultService) GetMethodName

func (s *DefaultService) GetMethodName() string

GetMethodName get method name

func (*DefaultService) GetServiceName

func (s *DefaultService) GetServiceName() string

GetServiceName get service name

func (*DefaultService) NewParameter

func (s *DefaultService) NewParameter() proto.Message

NewParameter no long will be used

type ErrorContext

type ErrorContext struct {
	// contains filtered or unexported fields
}

ErrorContext

type HaRpcClient

type HaRpcClient struct {
	// contains filtered or unexported fields
}

HaRpcClient high avialbe RpcClient

func NewHaRpcCient

func NewHaRpcCient(connections []Connection) (*HaRpcClient, error)

NewHaRpcCient

func NewHaRpcCientWithTimewheelSetting

func NewHaRpcCientWithTimewheelSetting(connections []Connection, timewheelInterval time.Duration, timewheelSlot uint16) (*HaRpcClient, error)

NewHaRpcCient

func (*HaRpcClient) Close

func (c *HaRpcClient) Close()

Close do close all client

func (*HaRpcClient) SendRpcRequest

func (c *HaRpcClient) SendRpcRequest(rpcInvocation *RpcInvocation, responseMessage proto.Message) (*RpcDataPackage, error)

SendRpcRequest send rpc request by elect one client

func (*HaRpcClient) SendRpcRequestWithTimeout

func (c *HaRpcClient) SendRpcRequestWithTimeout(timeout time.Duration, rpcInvocation *RpcInvocation, responseMessage proto.Message) (*RpcDataPackage, error)

SendRpcRequest send rpc request by elect one client with timeout feature

type Header struct {
	MagicCode   []byte
	MessageSize int32
	MetaSize    int32
}

RPC header content

func EmptyHead

func EmptyHead() *Header

EmptyHead return a empty head with default value

func (*Header) GetMagicCode

func (h *Header) GetMagicCode() []byte

func (*Header) GetMessageSize

func (h *Header) GetMessageSize() int32

func (*Header) GetMetaSize

func (h *Header) GetMetaSize() int32

func (*Header) Read

func (h *Header) Read(bytes []byte) error

Read read byte array

func (*Header) SetMagicCode

func (h *Header) SetMagicCode(MagicCode []byte)

func (*Header) SetMessageSize

func (h *Header) SetMessageSize(MessageSize int32)

func (*Header) SetMetaSize

func (h *Header) SetMetaSize(MetaSize int32)

func (*Header) Write

func (h *Header) Write() ([]byte, error)

Convert Header struct to byte array

type HttpServer

type HttpServer struct {
	// contains filtered or unexported fields
}

func (*HttpServer) ServeHTTP

func (h *HttpServer) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP to serve http reqeust and response to process http rpc handle

type HttpStatusView

type HttpStatusView struct {
	// contains filtered or unexported fields
}

HttpStatusView

func (*HttpStatusView) QpsDataStatus

func (hsv *HttpStatusView) QpsDataStatus(c context.Context, method *RPCMethod) (*QpsData, context.Context)

func (*HttpStatusView) Status

type PbFieldMeta

type PbFieldMeta struct {
	Name         string         `json:"name,omitempty"`
	Tag          int            `json:"tag,omitempty"`
	Type         string         `json:"type,omitempty"`
	Opt          string         `json:"opt,omitempty"`     // opt or req
	Version      string         `json:"version,omitempty"` // proto2 or proto3
	SubFieldMeta []*PbFieldMeta `json:"sub_field_meta,omitempty"`
	HasSub       bool           `json:"has_sub,omitempty"`
}

type QpsData

type QpsData struct {
	Qpsinfo map[int64]int32 `` /* 157-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*QpsData) Descriptor deprecated

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

Deprecated: Use QpsData.ProtoReflect.Descriptor instead.

func (*QpsData) GetQpsinfo

func (x *QpsData) GetQpsinfo() map[int64]int32

func (*QpsData) ProtoMessage

func (*QpsData) ProtoMessage()

func (*QpsData) ProtoReflect

func (x *QpsData) ProtoReflect() protoreflect.Message

func (*QpsData) Reset

func (x *QpsData) Reset()

func (*QpsData) String

func (x *QpsData) String() string

type RPCFN

type RPCFN func(msg proto.Message, attachment []byte, logId *int64) (proto.Message, []byte, error)

type RPCMethod

type RPCMethod struct {
	Service        string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"`
	Method         string `protobuf:"bytes,2,opt,name=method,proto3" json:"method,omitempty"`
	InTypeMeta     string `protobuf:"bytes,3,opt,name=intype,proto3" json:"intype,omitempty"`
	ReturnTypeMeta string `protobuf:"bytes,4,opt,name=returntype,proto3" json:"returntype,omitempty"`
	// contains filtered or unexported fields
}

func (*RPCMethod) Descriptor deprecated

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

Deprecated: Use RPCMethod.ProtoReflect.Descriptor instead.

func (*RPCMethod) GetInTypeMeta

func (x *RPCMethod) GetInTypeMeta() string

func (*RPCMethod) GetMethod

func (x *RPCMethod) GetMethod() string

func (*RPCMethod) GetReturnTypeMeta

func (x *RPCMethod) GetReturnTypeMeta() string

func (*RPCMethod) GetService

func (x *RPCMethod) GetService() string

func (*RPCMethod) ProtoMessage

func (*RPCMethod) ProtoMessage()

func (*RPCMethod) ProtoReflect

func (x *RPCMethod) ProtoReflect() protoreflect.Message

func (*RPCMethod) Reset

func (x *RPCMethod) Reset()

func (*RPCMethod) String

func (x *RPCMethod) String() string

type RPCMethodReuqestStatus

type RPCMethodReuqestStatus struct {
	QpsStatus map[int64]int32
}

RPCMethodReuqestStatus

type RPCRequestStatus

type RPCRequestStatus struct {
	Methods map[string]*RPCMethodReuqestStatus
	// contains filtered or unexported fields
}

RPCRequestStatus

func NewRPCRequestStatus

func NewRPCRequestStatus(services map[string]Service) *RPCRequestStatus

NewRPCRequestStatus

func (*RPCRequestStatus) RequestIn

func (r *RPCRequestStatus) RequestIn(methodName string, t time.Time, count int) error

RequestIn

func (*RPCRequestStatus) Start

func (r *RPCRequestStatus) Start() error

Start

func (*RPCRequestStatus) Stop

func (r *RPCRequestStatus) Stop()

Stop

type RPCStatus

type RPCStatus struct {
	Host            string       `protobuf:"bytes,1,opt,name=host,proto3" json:"host,omitempty"`
	Port            int32        `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"`
	TimeoutSenconds int32        `protobuf:"varint,3,opt,name=timeout,proto3" json:"timeout,omitempty"`
	Methods         []*RPCMethod `protobuf:"bytes,4,rep,name=methods,proto3" json:"methods,omitempty"`
	// contains filtered or unexported fields
}

func (*RPCStatus) Descriptor deprecated

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

Deprecated: Use RPCStatus.ProtoReflect.Descriptor instead.

func (*RPCStatus) GetHost

func (x *RPCStatus) GetHost() string

func (*RPCStatus) GetMethods

func (x *RPCStatus) GetMethods() []*RPCMethod

func (*RPCStatus) GetPort

func (x *RPCStatus) GetPort() int32

func (*RPCStatus) GetTimeout

func (x *RPCStatus) GetTimeout() int32

func (*RPCStatus) ProtoMessage

func (*RPCStatus) ProtoMessage()

func (*RPCStatus) ProtoReflect

func (x *RPCStatus) ProtoReflect() protoreflect.Message

func (*RPCStatus) Reset

func (x *RPCStatus) Reset()

func (*RPCStatus) String

func (x *RPCStatus) String() string

type Readable

type Readable interface {
	Read(bytes []byte) error
}

Readable is the interface that deserialize from []byte if errror ocurres should return non-nil error

type Request

type Request struct {
	ServiceName       string                    `protobuf:"bytes,1,opt,name=service_name,json=serviceName,proto3" json:"service_name,omitempty"`
	MethodName        string                    `protobuf:"bytes,2,opt,name=method_name,json=methodName,proto3" json:"method_name,omitempty"`
	LogId             int64                     `protobuf:"varint,3,opt,name=log_id,json=logId,proto3" json:"log_id,omitempty"`
	TraceId           int64                     `protobuf:"varint,4,opt,name=traceId,proto3" json:"traceId,omitempty"`
	SpanId            int64                     `protobuf:"varint,5,opt,name=spanId,proto3" json:"spanId,omitempty"`
	ParentSpanId      int64                     `protobuf:"varint,6,opt,name=parentSpanId,proto3" json:"parentSpanId,omitempty"`
	RpcRequestMetaExt []*RpcRequestMetaExtField `protobuf:"bytes,7,rep,name=rpcRequestMetaExt,proto3" json:"rpcRequestMetaExt,omitempty"`
	ExtraParam        []byte                    `protobuf:"bytes,110,opt,name=extraParam,proto3" json:"extraParam,omitempty"`
	// contains filtered or unexported fields
}

func (*Request) Descriptor deprecated

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

Deprecated: Use Request.ProtoReflect.Descriptor instead.

func (*Request) GetExtraParam

func (x *Request) GetExtraParam() []byte

func (*Request) GetLogId

func (x *Request) GetLogId() int64

func (*Request) GetMethodName

func (x *Request) GetMethodName() string

func (*Request) GetParentSpanId

func (x *Request) GetParentSpanId() int64

func (*Request) GetRpcRequestMetaExt

func (x *Request) GetRpcRequestMetaExt() []*RpcRequestMetaExtField

func (*Request) GetServiceName

func (x *Request) GetServiceName() string

func (*Request) GetSpanId

func (x *Request) GetSpanId() int64

func (*Request) GetTraceId

func (x *Request) GetTraceId() int64

func (*Request) ProtoMessage

func (*Request) ProtoMessage()

func (*Request) ProtoReflect

func (x *Request) ProtoReflect() protoreflect.Message

func (*Request) Reset

func (x *Request) Reset()

func (*Request) String

func (x *Request) String() string

type Response

type Response struct {
	ErrorCode int32  `protobuf:"varint,1,opt,name=error_code,json=errorCode,proto3" json:"error_code,omitempty"`
	ErrorText string `protobuf:"bytes,2,opt,name=error_text,json=errorText,proto3" json:"error_text,omitempty"`
	// contains filtered or unexported fields
}

func (*Response) Descriptor deprecated

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

Deprecated: Use Response.ProtoReflect.Descriptor instead.

func (*Response) GetErrorCode

func (x *Response) GetErrorCode() int32

func (*Response) GetErrorText

func (x *Response) GetErrorText() string

func (*Response) ProtoMessage

func (*Response) ProtoMessage()

func (*Response) ProtoReflect

func (x *Response) ProtoReflect() protoreflect.Message

func (*Response) Reset

func (x *Response) Reset()

func (*Response) String

func (x *Response) String() string

type ResponseData

type ResponseData struct {
	ErrNo   int         `json:"errno"`
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

ResponseData

type RpcClient

type RpcClient struct {
	Session Connection
	// contains filtered or unexported fields
}

RPC client invoke

func NewRpcCient

func NewRpcCient(connection Connection) (*RpcClient, error)

NewRpcCient new rpc client

func NewRpcCientWithTimeWheelSetting

func NewRpcCientWithTimeWheelSetting(connection Connection, timewheelInterval time.Duration, timewheelSlot uint16) (*RpcClient, error)

NewRpcCientWithTimeWheelSetting new rpc client with set timewheel settings

func (*RpcClient) Close

func (c *RpcClient) Close()

define client methods Close close client with time wheel

func (*RpcClient) SendRpcRequest

func (c *RpcClient) SendRpcRequest(rpcInvocation *RpcInvocation, responseMessage proto.Message) (*RpcDataPackage, error)

SendRpcRequest send rpc request to remote server

func (*RpcClient) SendRpcRequestAsyc

func (c *RpcClient) SendRpcRequestAsyc(rpcInvocation *RpcInvocation, responseMessage proto.Message) <-chan *RpcResult

SendRpcRequestAsyc send rpc request to remote server in asynchronous way

func (*RpcClient) SendRpcRequestWithTimeout

func (c *RpcClient) SendRpcRequestWithTimeout(timeout time.Duration, rpcInvocation *RpcInvocation, responseMessage proto.Message) (*RpcDataPackage, error)

SendRpcRequest send rpc request to remote server

type RpcDataPackage

type RpcDataPackage struct {
	Head       *Header  // rpc head
	Meta       *RpcMeta // rpc meta
	Data       []byte
	Attachment []byte
	// contains filtered or unexported fields
}
Data package for baidu RPC.
all request and response data package should apply this.

----------------------------------- | Head | Meta | Data | Attachment | -----------------------------------

1. <Head> with fixed 12 byte length as follow format ---------------------------------------------- | PRPC | MessageSize(int32) | MetaSize(int32) | ---------------------------------------------- MessageSize = totalSize - 12(Fixed Head Size) MetaSize = Meta object size

2. <Meta> body proto description as follow

message RpcMeta {
    optional Request request = 1;
    optional Response response = 2;
    optional int32 compress_type = 3; // 0:nocompress 1:Snappy 2:gzip
    optional int64 correlation_id = 4;
    optional int32 attachment_size = 5;
    optional ChuckInfo chuck_info = 6;
    optional bytes authentication_data = 7;
};

message Request {
    required string service_name = 1;
    required string method_name = 2;
    optional int64 log_id = 3;
	optional int64 traceId=4;
	optional int64 spanId=5;
	optional int64 parentSpanId=6;
	repeat RpcRequestMetaExtField extFields = 7;
};

message RpcRequestMetaExtField {
	optional string key = 1;
	optional string value = 2;
}

message Response {
    optional int32 error_code = 1;
    optional string error_text = 2;
};

messsage ChuckInfo {
    required int64 stream_id = 1;
    required int64 chunk_id = 2;
};

3. <Data> customize transport data message.

4. <Attachment> attachment body data message

func NewRpcDataPackage

func NewRpcDataPackage() *RpcDataPackage

NewRpcDataPackage returns a new RpcDataPackage and init all fields

func (*RpcDataPackage) AuthenticationData

func (r *RpcDataPackage) AuthenticationData(authenticationData []byte) *RpcDataPackage

AuthenticationData set authentication data

func (*RpcDataPackage) ChuckInfo

func (r *RpcDataPackage) ChuckInfo(streamId int64, chunkId int64) *RpcDataPackage

ChuckInfo set chuck info

func (*RpcDataPackage) Chunk

func (r *RpcDataPackage) Chunk(chunkSize int) []*RpcDataPackage

Chunk chunk to small packages by chunk size

func (*RpcDataPackage) Clear

func (r *RpcDataPackage) Clear()

Clear to clear and init all fields

func (*RpcDataPackage) ClearChunkStatus

func (r *RpcDataPackage) ClearChunkStatus()

ClearChunkStatus to clear chunk status

func (*RpcDataPackage) CompressType

func (r *RpcDataPackage) CompressType(compressType int32) *RpcDataPackage

CompressType set compress type data

func (*RpcDataPackage) CorrelationId

func (r *RpcDataPackage) CorrelationId(correlationId int64) *RpcDataPackage

CorrelationId set correlationId data

func (*RpcDataPackage) ErrorCode

func (r *RpcDataPackage) ErrorCode(errorCode int32) *RpcDataPackage

ErrorCode set error code field

func (*RpcDataPackage) ErrorText

func (r *RpcDataPackage) ErrorText(errorText string) *RpcDataPackage

ErrorText set error text field

func (*RpcDataPackage) ExtraParams

func (r *RpcDataPackage) ExtraParams(extraParams []byte) *RpcDataPackage

ExtraParams set extra parameters field

func (*RpcDataPackage) GetAttachment

func (r *RpcDataPackage) GetAttachment() []byte

GetAttachment return attachment field

func (*RpcDataPackage) GetChunkStreamId

func (r *RpcDataPackage) GetChunkStreamId() int64

GetChunkStreamId return chunk stream id

func (*RpcDataPackage) GetData

func (r *RpcDataPackage) GetData() []byte

GetData return data field

func (*RpcDataPackage) GetHead

func (r *RpcDataPackage) GetHead() *Header

GetHead return Header data

func (*RpcDataPackage) GetLogId

func (r *RpcDataPackage) GetLogId() int64

GetLogId return log id

func (*RpcDataPackage) GetMagicCode

func (r *RpcDataPackage) GetMagicCode() string

GetMagicCode return magic code value

func (*RpcDataPackage) GetMeta

func (r *RpcDataPackage) GetMeta() *RpcMeta

GetMeta return RpcMeta data

func (*RpcDataPackage) GetParentSpanId

func (r *RpcDataPackage) GetParentSpanId() int64

GetParentSpanId return parent span id

func (*RpcDataPackage) GetRpcRequestMetaExt

func (r *RpcDataPackage) GetRpcRequestMetaExt() map[string]string

GetRpcRequestMetaExt return rpc request meta extendstion

func (*RpcDataPackage) GetSpanId

func (r *RpcDataPackage) GetSpanId() int64

GetSpanId return span id

func (*RpcDataPackage) GetTraceId

func (r *RpcDataPackage) GetTraceId() int64

GetTraceId return trace id

func (*RpcDataPackage) IsChunkPackage

func (r *RpcDataPackage) IsChunkPackage() bool

IsChunkPackage return if chunk package type

func (*RpcDataPackage) IsFinalPackage

func (r *RpcDataPackage) IsFinalPackage() bool

IsFinalPackage return if the final chunk package

func (*RpcDataPackage) LogId

func (r *RpcDataPackage) LogId(logId int64) *RpcDataPackage

LogId set log id data

func (*RpcDataPackage) MagicCode

func (r *RpcDataPackage) MagicCode(magicCode string)

MagicCode set magic code field

func (*RpcDataPackage) MethodName

func (r *RpcDataPackage) MethodName(methodName string) *RpcDataPackage

MethodName set method name field

func (*RpcDataPackage) ParentSpanId

func (r *RpcDataPackage) ParentSpanId(parentSpanId int64) *RpcDataPackage

ParentSpanId set parent span id

func (*RpcDataPackage) Read

func (r *RpcDataPackage) Read(b []byte) error

Read and parse data from target byte slice

func (*RpcDataPackage) ReadIO

func (r *RpcDataPackage) ReadIO(rw io.Reader) error

Read byte array and initialize RpcPackage

func (*RpcDataPackage) RpcRequestMetaExt

func (r *RpcDataPackage) RpcRequestMetaExt(ext map[string]string) *RpcDataPackage

RpcRequestMetaExt set rpc request meta extendsion fields

func (*RpcDataPackage) ServiceName

func (r *RpcDataPackage) ServiceName(serviceName string) *RpcDataPackage

ServiceName set service name field

func (*RpcDataPackage) SetAttachment

func (r *RpcDataPackage) SetAttachment(Attachment []byte) *RpcDataPackage

SetAttachment set attachment

func (*RpcDataPackage) SetData

func (r *RpcDataPackage) SetData(Data []byte) *RpcDataPackage

SetData set data

func (*RpcDataPackage) SpanId

func (r *RpcDataPackage) SpanId(spanId int64) *RpcDataPackage

SpanId set span id

func (*RpcDataPackage) TraceId

func (r *RpcDataPackage) TraceId(traceId int64) *RpcDataPackage

TraceId set trace id data

func (*RpcDataPackage) Write

func (r *RpcDataPackage) Write() ([]byte, error)

Convert RpcPackage to byte array

func (*RpcDataPackage) WriteIO

func (r *RpcDataPackage) WriteIO(rw io.Writer) error

Convert RpcPackage to byte array

type RpcDataPackageCodec

type RpcDataPackageCodec[S, R *RpcDataPackage] struct {
	// contains filtered or unexported fields
}

Codec implements for RpcDataPackage.

func (*RpcDataPackageCodec[S, R]) Close

func (r *RpcDataPackageCodec[S, R]) Close() error

do close connection io return non-nil if any error ocurred while doing close

func (*RpcDataPackageCodec[S, R]) Receive

func (r *RpcDataPackageCodec[S, R]) Receive() (*RpcDataPackage, error)

receive serialized data to target server by connection IO return param: 1. RpcDataPackage unserialized from connection io. or nil if exception found 2. a non-nil error if any io exception occurred

func (*RpcDataPackageCodec[S, R]) Send

func (r *RpcDataPackageCodec[S, R]) Send(dataPackage *RpcDataPackage) error

send serialized data to target server by connection IO msg: param 'msg' must type of RpcDataPackage

func (*RpcDataPackageCodec[S, R]) SetTimeout

func (r *RpcDataPackageCodec[S, R]) SetTimeout(timeout *time.Duration)

set connection io read and write dead line

type RpcDataPackageProtocol

type RpcDataPackageProtocol[S, R *RpcDataPackage] struct {
	// contains filtered or unexported fields
}

Protocol codec factory object for RpcDataPackage

func NewRpcDataPackageProtocol

func NewRpcDataPackageProtocol[S, R *RpcDataPackage]() (*RpcDataPackageProtocol[S, R], error)

NewRpcDataPackageProtocol create a RpcDataPackageProtocol and start timewheel

func (*RpcDataPackageProtocol[S, R]) NewCodec

func (*RpcDataPackageProtocol[S, R]) Stop

func (r *RpcDataPackageProtocol[S, R]) Stop()

Stop

type RpcInvocation

type RpcInvocation struct {
	ServiceName       *string
	MethodName        *string
	ParameterIn       *proto.Message
	Attachment        []byte
	LogId             *int64
	CompressType      *int32
	AuthenticateData  []byte
	ChunkSize         uint32
	TraceId           int64
	SpanId            int64
	ParentSpanId      int64
	RpcRequestMetaExt map[string]string
}

RpcInvocation define rpc invocation

func NewRpcInvocation

func NewRpcInvocation(serviceName, methodName *string) *RpcInvocation

NewRpcInvocation create RpcInvocation with service name and method name

func (*RpcInvocation) GetRequestRpcDataPackage

func (r *RpcInvocation) GetRequestRpcDataPackage() (*RpcDataPackage, error)

GetRequestRpcDataPackage

func (*RpcInvocation) SetParameterIn

func (r *RpcInvocation) SetParameterIn(parameterIn proto.Message)

SetParameterIn

type RpcMeta

type RpcMeta struct {
	Request            *Request   `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"`
	Response           *Response  `protobuf:"bytes,2,opt,name=response,proto3" json:"response,omitempty"`
	CompressType       int32      `protobuf:"varint,3,opt,name=compress_type,json=compressType,proto3" json:"compress_type,omitempty"` // 0:nocompress 1:Snappy 2:gzip
	CorrelationId      int64      `protobuf:"varint,4,opt,name=correlation_id,json=correlationId,proto3" json:"correlation_id,omitempty"`
	AttachmentSize     int32      `protobuf:"varint,5,opt,name=attachment_size,json=attachmentSize,proto3" json:"attachment_size,omitempty"`
	ChuckInfo          *ChunkInfo `protobuf:"bytes,6,opt,name=chuck_info,json=chuckInfo,proto3" json:"chuck_info,omitempty"`
	AuthenticationData []byte     `protobuf:"bytes,7,opt,name=authentication_data,json=authenticationData,proto3" json:"authentication_data,omitempty"`
	// contains filtered or unexported fields
}

func (*RpcMeta) Descriptor deprecated

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

Deprecated: Use RpcMeta.ProtoReflect.Descriptor instead.

func (*RpcMeta) GetAttachmentSize

func (x *RpcMeta) GetAttachmentSize() int32

func (*RpcMeta) GetAuthenticationData

func (x *RpcMeta) GetAuthenticationData() []byte

func (*RpcMeta) GetChuckInfo

func (x *RpcMeta) GetChuckInfo() *ChunkInfo

func (*RpcMeta) GetCompressType

func (x *RpcMeta) GetCompressType() int32

func (*RpcMeta) GetCorrelationId

func (x *RpcMeta) GetCorrelationId() int64

func (*RpcMeta) GetRequest

func (x *RpcMeta) GetRequest() *Request

func (*RpcMeta) GetResponse

func (x *RpcMeta) GetResponse() *Response

func (*RpcMeta) ProtoMessage

func (*RpcMeta) ProtoMessage()

func (*RpcMeta) ProtoReflect

func (x *RpcMeta) ProtoReflect() protoreflect.Message

func (*RpcMeta) Reset

func (x *RpcMeta) Reset()

func (*RpcMeta) String

func (x *RpcMeta) String() string

type RpcRequestMetaExtField

type RpcRequestMetaExtField struct {
	Key   string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

func (*RpcRequestMetaExtField) Descriptor deprecated

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

Deprecated: Use RpcRequestMetaExtField.ProtoReflect.Descriptor instead.

func (*RpcRequestMetaExtField) GetKey

func (x *RpcRequestMetaExtField) GetKey() string

func (*RpcRequestMetaExtField) GetValue

func (x *RpcRequestMetaExtField) GetValue() string

func (*RpcRequestMetaExtField) ProtoMessage

func (*RpcRequestMetaExtField) ProtoMessage()

func (*RpcRequestMetaExtField) ProtoReflect

func (x *RpcRequestMetaExtField) ProtoReflect() protoreflect.Message

func (*RpcRequestMetaExtField) Reset

func (x *RpcRequestMetaExtField) Reset()

func (*RpcRequestMetaExtField) String

func (x *RpcRequestMetaExtField) String() string

type RpcResult

type RpcResult struct {
	// contains filtered or unexported fields
}

RpcResult Rpc response result from client request api under asynchronous way

func (*RpcResult) Get

func (rr *RpcResult) Get() proto.Message

func (*RpcResult) GetErr

func (rr *RpcResult) GetErr() error

func (*RpcResult) GetRpcDataPackage

func (rr *RpcResult) GetRpcDataPackage() *RpcDataPackage

type Server

type Server interface {
	Start() error
	Stop() error
	Register(service *Service) (bool, error)
}

type ServerMeta

type ServerMeta struct {
	Host               *string
	Port               *int
	IdleTimeoutSeconds *int
	QPSExpireInSecs    int
	ChunkSize          uint32
	TimeoutSeconds     uint32
}

type Service

type Service interface {
	/*
	   RPC service call back method.
	   message : parameter in from RPC client or 'nil' if has no parameter
	   attachment : attachment content from RPC client or 'nil' if has no attachment
	   logId : with a int64 type log sequence id from client or 'nil if has no logId
	   return:
	   [0] message return back to RPC client or 'nil' if need not return method response
	   [1] attachment return back to RPC client or 'nil' if need not return attachemnt
	   [2] return with any error or 'nil' represents success
	*/
	DoService(message proto.Message, attachment []byte, logId *int64) (proto.Message, []byte, error)
	GetServiceName() string
	GetMethodName() string
	NewParameter() proto.Message
}

Service rpc service

type TCPConnection

type TCPConnection struct {
	// contains filtered or unexported fields
}

TCPConnection simple tcp based connection implementation

func NewTCPConnection

func NewTCPConnection(url URL, timeout *time.Duration) (*TCPConnection, error)

Create a new TCPConnection and try to connect to target server by URL.

func (*TCPConnection) Close

func (c *TCPConnection) Close() error

Close close connection

func (*TCPConnection) GetId

func (c *TCPConnection) GetId() uint64

func (*TCPConnection) Receive

func (c *TCPConnection) Receive() (*RpcDataPackage, error)

Receive data from connection

func (*TCPConnection) Reconnect

func (c *TCPConnection) Reconnect() error

Reconnect do connect by saved info

func (*TCPConnection) Send

func (c *TCPConnection) Send(rpcDataPackage *RpcDataPackage) error

Send data to connection

func (*TCPConnection) SendReceive

func (c *TCPConnection) SendReceive(rpcDataPackage *RpcDataPackage) (*RpcDataPackage, error)

SendReceive send data to connect and block wait data recevie

func (*TCPConnection) TestConnection

func (c *TCPConnection) TestConnection() error

type TCPConnectionPool

type TCPConnectionPool struct {
	Config *pool.ObjectPoolConfig
	// contains filtered or unexported fields
}

func NewDefaultTCPConnectionPool

func NewDefaultTCPConnectionPool(url URL, timeout *time.Duration) (*TCPConnectionPool, error)

func NewTCPConnectionPool

func NewTCPConnectionPool(url URL, timeout *time.Duration, config *pool.ObjectPoolConfig) (*TCPConnectionPool, error)

func (*TCPConnectionPool) Close

func (c *TCPConnectionPool) Close() error

func (*TCPConnectionPool) GetNumActive

func (c *TCPConnectionPool) GetNumActive() int

func (*TCPConnectionPool) Receive

func (c *TCPConnectionPool) Receive() (*RpcDataPackage, error)

Receive

func (*TCPConnectionPool) Reconnect

func (c *TCPConnectionPool) Reconnect() error

Reconnect do connect by saved info

func (*TCPConnectionPool) Send

func (c *TCPConnectionPool) Send(rpcDataPackage *RpcDataPackage) error

Send

func (*TCPConnectionPool) SendReceive

func (c *TCPConnectionPool) SendReceive(rpcDataPackage *RpcDataPackage) (*RpcDataPackage, error)

type TcpServer

type TcpServer struct {
	EnablePerformanceLog bool
	// contains filtered or unexported fields
}

TcpServer RPC server base on tcp transport

func NewTpcServer

func NewTpcServer(serverMeta *ServerMeta) *TcpServer

NewTpcServer

func (*TcpServer) EnableHttp

func (s *TcpServer) EnableHttp()

EnableHttp

func (*TcpServer) Register

func (s *TcpServer) Register(service interface{}) (bool, error)

Register register RPC service

func (*TcpServer) RegisterName

func (s *TcpServer) RegisterName(name string, rcvr interface{}) (bool, error)

RegisterName register publishes in the server with specified name for its set of methods of the receiver value that satisfy the following conditions:

  • exported method of exported type
  • one argument, exported type and should be the type implements from proto.Message
  • one return value, of type proto.Message

It returns an error if the receiver is not an exported type or has no suitable methods. It also logs the error using package log. The client accesses each method using a string of the form "Type.Method", where Type is the receiver's concrete type.

func (*TcpServer) RegisterNameWithMethodMapping

func (s *TcpServer) RegisterNameWithMethodMapping(name string, rcvr interface{}, mapping map[string]string) (bool, error)

RegisterNameWithMethodMapping call RegisterName with method name mapping map

func (*TcpServer) RegisterRpc

func (s *TcpServer) RegisterRpc(sname, mname string, callback RPCFN, inType proto.Message) (bool, error)

RegisterRpc register Rpc direct

func (*TcpServer) SetAuthService

func (s *TcpServer) SetAuthService(authservice AuthService)

SetAuthService set authenticate service

func (*TcpServer) SetTraceService

func (s *TcpServer) SetTraceService(traceService TraceService)

SetTraceService set trace service

func (*TcpServer) Start

func (s *TcpServer) Start() error

func (*TcpServer) StartAndBlock

func (s *TcpServer) StartAndBlock() error

func (*TcpServer) StartServer

func (s *TcpServer) StartServer(l net.Listener) error

StartServer start server with net.Listener

func (*TcpServer) Stop

func (s *TcpServer) Stop(ctx context.Context) error

Stop do stop rpc server

type TraceInfo

type TraceInfo struct {
	TraceId           int64
	SpanId            int64
	ParentSpanId      int64
	RpcRequestMetaExt map[string]string
}

type TraceService

type TraceService interface {
	Trace(service, name string, traceInfo *TraceInfo) *TraceInfo
}

TraceService to monitor trace info and return trace info back

type URL

type URL struct {
	Host *string
	Port *int
}

URL with host and port attribute

func (*URL) SetHost

func (u *URL) SetHost(host *string) *URL

SetHost set host name

func (*URL) SetPort

func (u *URL) SetPort(port *int) *URL

SetPort set port

type Writable

type Writable interface {
	Write() ([]byte, error)
}

Writable is the interface that do serialize to []byte if errror ocurres should return non-nil error

Jump to

Keyboard shortcuts

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