drpc

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 38 Imported by: 2

Documentation

Index

Constants

View Source
const (
	CodeUnknownError        int32 = -1
	CodeOK                  int32 = 0      // nil error (ok)
	CodeNoError             int32 = CodeOK // nil error (ok)
	CodeInvalidOp           int32 = 1
	CodeWrongConn           int32 = 100
	CodeConnClosed          int32 = 102
	CodeWriteFailed         int32 = 104
	CodeDialFailed          int32 = 105
	CodeBadMessage          int32 = 400
	CodeUnauthorized        int32 = 401
	CodeNotFound            int32 = 404
	CodeMTypeNotAllowed     int32 = 405
	CodeHandleTimeout       int32 = 408
	CodeInternalServerError int32 = 500
	CodeBadGateway          int32 = 502

	CodeConflict int32 = 409
)

框架保留 Status code 建议自定义代码大于1000 未知错误:-1 发送错误: 100-199 消息处理错误: 400-499 接收错误: 500-599

Variables

View Source
var (
	TypeText = message.TypeText

	MetaRealIP          = message.MetaRealIP
	MetaAcceptBodyCodec = message.MetaAcceptBodyCodec

	TypeUndefined = message.TypeUndefined
	TypeCall      = message.TypeCall
	TypeReply     = message.TypeReply
	TypePush      = message.TypePush
	TypeAuthCall  = message.TypeAuthCall
	TypeAuthReply = message.TypeAuthReply
)
View Source
var (
	GetMessage = message.GetMessage
	PutMessage = message.PutMessage
)
View Source
var (
	// WithNothing nothing to do.
	//  func WithNothing() MessageSetting
	WithNothing = message.WithNothing
	// WithStatus sets the message status.
	// TYPE:
	//  func WithStatus(stat *Status) MessageSetting
	WithStatus = message.WithStatus
	// WithContext sets the message handling context.
	//  func WithContext(ctx context.Context) MessageSetting
	WithContext = message.WithContext
	// WithServiceMethod sets the message service method.
	// SUGGEST: max len ≤ 255!
	//  func WithServiceMethod(serviceMethod string) MessageSetting
	WithServiceMethod = message.WithServiceMethod
	// WithSetMeta sets 'key=value' metadata argument.
	// SUGGEST: urlencoded string max len ≤ 65535!
	//  func WithSetMeta(key, value string) MessageSetting
	WithSetMeta = message.WithSetMeta

	WithSetMetas = message.WithSetMetas
	// WithDelMeta deletes metadata argument.
	//   func WithDelMeta(key string) MessageSetting
	WithDelMeta = message.WithDelMeta
	// WithBodyCodec sets the body codec.
	//  func WithBodyCodec(bodyCodec byte) MessageSetting
	WithBodyCodec = message.WithBodyCodec
	// WithBody sets the body object.
	//  func WithBody(body interface{}) MessageSetting
	WithBody = message.WithBody
	// WithNewBody resets the function of geting body.
	//  NOTE: newBodyFunc is only for reading form connection.
	//  func WithNewBody(newBodyFunc socket.NewBodyFunc) MessageSetting
	WithNewBody = message.WithNewBody

	// WithTFilterPipe 设置传输过滤器.
	// 提示: 如果filterID未注册,则会产生Panic错误。
	// 建议: 最大长度不能超过255!
	//  func WithTFilterPipe(filterID ...byte) MessageSetting
	WithTFilterPipe = message.WithTFilterPipe

	GetAcceptBodyCodec = message.GetAcceptBodyCodec
)
View Source
var DefaultProtoFunc = socket.DefaultProtoFunc

DefaultProtoFunc 默认传输协议

View Source
var ErrListenClosed = errors.New("listener is closed")
View Source
var GetReadLimit = message.MsgSizeLimit

GetReadLimit 获取消息最大长度限制

View Source
var (
	NewStatus = status.New
)
View Source
var SetDefaultProtoFunc = socket.SetDefaultProtoFunc

SetDefaultProtoFunc 设置默认传输协议

View Source
var SetReadLimit = message.SetMsgSizeLimit

SetReadLimit 设置消息最大长度限制

View Source
var SetSocketKeepAlive = socket.SetKeepAlive

SetSocketKeepAlive 开启关闭死链检测

View Source
var SetSocketKeepAlivePeriod = socket.SetKeepAlivePeriod

SetSocketKeepAlivePeriod 死链检测间隔时间

View Source
var SetSocketNoDelay = socket.SetNoDelay

SetSocketNoDelay 开启关闭no delay算法

View Source
var SetSocketReadBuffer = socket.SetReadBuffer

SetSocketReadBuffer 设置链接读缓冲区长度

View Source
var SetSocketWriteBuffer = socket.SetWriteBuffer

SetSocketWriteBuffer 设置链接写缓冲区长度

View Source
var SocketReadBuffer = socket.ReadBuffer

SocketReadBuffer 获取链接读缓冲区长度

View Source
var SocketWriteBuffer = socket.WriteBuffer

SocketWriteBuffer 获取链接写缓冲区长度

Functions

func CodeText

func CodeText(statCode int32) string

func DefaultBodyCodec

func DefaultBodyCodec() codec.Codec

DefaultBodyCodec 获取当前默认消息体编码格式

func GetLogger added in v0.5.1

func GetLogger() *glog.Logger

GetLogger 获取drpc组件使用的logger对象

func HTTPServiceMethodMapper

func HTTPServiceMethodMapper(prefix, name string) string

HTTPServiceMethodMapper service method名称的映射规则,使用"/"做分隔符 默认的映射规则 生成的serviceMethod类似于:/pay/alipay/app

struct或者func的名字转换成service methods的规则如下:
`AaBb` -> `/aa_bb`
`ABcXYz` -> `/abc_xyz`
`Aa__Bb` -> `/aa_bb`
`aa__bb` -> `/aa_bb`
`ABC__XYZ` -> `/abc_xyz`
`Aa_Bb` -> `/aa/bb`
`aa_bb` -> `/aa/bb`
`ABC_XYZ` -> `/abc/xyz`

func IsConnError added in v0.6.0

func IsConnError(stat *Status) bool

IsConnError 判断是否是链接出错

func NewInheritedListener

func NewInheritedListener(addr net.Addr, tlsConfig *tls.Config) (lis net.Listener, err error)

NewInheritedListener 创建一个支持优雅重启,支持继承监听的监听器

func RPCServiceMethodMapper added in v0.0.5

func RPCServiceMethodMapper(prefix, name string) string

RPCServiceMethodMapper service method名称的映射规则,使用"."做分隔符 生成的serviceMethod类似于:pay.alipay.app

struct或者func的名字转换成service methods的规则如下:
`AaBb` -> `AaBb`
`ABcXYz` -> `ABcXYz`
`Aa__Bb` -> `Aa_Bb`
`aa__bb` -> `aa_bb`
`ABC__XYZ` -> `ABC_XYZ`
`Aa_Bb` -> `Aa.Bb`
`aa_bb` -> `aa.bb`
`ABC_XYZ` -> `ABC.XYZ`

func SetDefaultBodyCodec

func SetDefaultBodyCodec(codecName string) error

SetDefaultBodyCodec 设置默认消息体编码格式

func SetLogger added in v0.5.0

func SetLogger(l *glog.Logger)

SetLogger 使用自定义的log

func SetServiceMethodMapper

func SetServiceMethodMapper(mapper ServiceMethodMapper)

SetServiceMethodMapper 设置路由路径的生成函数

func WithAcceptBodyCodec added in v0.0.3

func WithAcceptBodyCodec(bodyCodec byte) message.MsgSetting

WithAcceptBodyCodec sets the body codec that the sender wishes to accept. NOTE: If the specified codec is invalid, the receiver will ignore the mate data.

func WithRealIP added in v0.0.3

func WithRealIP(ip string) message.MsgSetting

Types

type AfterAcceptPlugin

type AfterAcceptPlugin interface {
	Plugin
	AfterAccept(EarlySession) *Status
}

AfterAcceptPlugin 作为服务端,接收到客户端的链接后触发该事件

type AfterCloseEndpointPlugin added in v0.0.5

type AfterCloseEndpointPlugin interface {
	Plugin
	AfterCloseEndpoint(Endpoint, error) error
}

AfterCloseEndpointPlugin 关闭Endpoint之后触发该事件

type AfterDialFailPlugin added in v0.0.4

type AfterDialFailPlugin interface {
	Plugin
	AfterDialFail(sess EarlySession, err error, isRedial bool) *Status
}

AfterDialFailPlugin 作为客户端链接到服务端失败以后触发该事件

type AfterDialPlugin

type AfterDialPlugin interface {
	Plugin
	AfterDial(sess EarlySession, isRedial bool) *Status
}

AfterDialPlugin 作为客户端链接到服务端成功以后触发该事件

type AfterDisconnectPlugin

type AfterDisconnectPlugin interface {
	Plugin
	AfterDisconnect(BaseSession) *Status
}

AfterDisconnectPlugin 断开会话以后触发该事件

type AfterListenPlugin

type AfterListenPlugin interface {
	Plugin
	AfterListen(net.Addr) error
}

AfterListenPlugin 服务端监听以后触发该事件

type AfterNewEndpointPlugin

type AfterNewEndpointPlugin interface {
	Plugin
	AfterNewEndpoint(EarlyEndpoint) error
}

AfterNewEndpointPlugin 创建Endpoint之后触发该事件

type AfterReadCallBodyPlugin

type AfterReadCallBodyPlugin interface {
	Plugin
	AfterReadCallBody(ReadCtx) *Status
}

AfterReadCallBodyPlugin 读取CALL消息的body之后触发该事件

type AfterReadCallHeaderPlugin

type AfterReadCallHeaderPlugin interface {
	Plugin
	AfterReadCallHeader(ReadCtx) *Status
}

AfterReadCallHeaderPlugin 读取CALL消息的Header之后触发该事件

type AfterReadPushBodyPlugin

type AfterReadPushBodyPlugin interface {
	Plugin
	AfterReadPushBody(ReadCtx) *Status
}

AfterReadPushBodyPlugin 读取PUSH消息body之后触发该事件

type AfterReadPushHeaderPlugin

type AfterReadPushHeaderPlugin interface {
	Plugin
	AfterReadPushHeader(ReadCtx) *Status
}

AfterReadPushHeaderPlugin 读取PUSH消息Header之后触发该事件

type AfterReadReplyBodyPlugin

type AfterReadReplyBodyPlugin interface {
	Plugin
	AfterReadReplyBody(ReadCtx) *Status
}

AfterReadReplyBodyPlugin 读取REPLY消息body之后触发该事件

type AfterReadReplyHeaderPlugin

type AfterReadReplyHeaderPlugin interface {
	Plugin
	AfterReadReplyHeader(ReadCtx) *Status
}

AfterReadReplyHeaderPlugin 读取REPLY消息Header之前触发该事件

type AfterRegRouterPlugin

type AfterRegRouterPlugin interface {
	Plugin
	AfterRegRouter(*Handler) error
}

AfterRegRouterPlugin 路由注册成功触发该事件

type AfterWriteCallPlugin

type AfterWriteCallPlugin interface {
	Plugin
	AfterWriteCall(WriteCtx) *Status
}

AfterWriteCallPlugin 写入CALL消息成功之后触发该事件

type AfterWritePushPlugin

type AfterWritePushPlugin interface {
	Plugin
	AfterWritePush(WriteCtx) *Status
}

AfterWritePushPlugin 写入PUSH消息成功之后触发该事件

type AfterWriteReplyPlugin

type AfterWriteReplyPlugin interface {
	Plugin
	AfterWriteReply(WriteCtx) *Status
}

AfterWriteReplyPlugin 写入Reply消息成功之后触发该事件

type BaseEndpoint

type BaseEndpoint interface {

	// Close 关闭该端点
	Close() (err error)

	// CountSession 统计该端点上的session数量
	CountSession() int

	// GetSession 获取指定ID的 session
	GetSession(sessionID string) (Session, bool)

	// RangeSession 循环迭代session
	RangeSession(fn func(sess Session) bool)

	// SetTLSConfig 设置证书配置
	SetTLSConfig(tlsConfig *tls.Config)

	// SetTLSConfigFromFile 从文件中读取证书并设置证书配置
	SetTLSConfigFromFile(tlsCertFile, tlsKeyFile string, insecureSkipVerifyForClient ...bool) error

	// TLSConfig tls配置对象
	TLSConfig() *tls.Config

	// PluginContainer 插件容器对象
	PluginContainer() *PluginContainer
}

type BaseSession

type BaseSession interface {
	Endpoint() Endpoint

	// ID 获取id
	ID() string

	// LocalAddr 本地地址
	LocalAddr() net.Addr

	// RemoteAddr 远端地址
	RemoteAddr() net.Addr

	// Swap 返回交换区的内容
	Swap() *gmap.Map
}

BaseSession 基础的session

type BeforeCloseEndpointPlugin added in v0.0.5

type BeforeCloseEndpointPlugin interface {
	Plugin
	BeforeCloseEndpoint(Endpoint) error
}

BeforeCloseEndpointPlugin 关闭Endpoint之前触发该事件

type BeforeDialPlugin added in v0.0.4

type BeforeDialPlugin interface {
	Plugin
	BeforeDial(addr string, isRedial bool) *Status
}

BeforeDialPlugin 作为客户端链接到服务端之前调用该事件

type BeforeNewEndpointPlugin

type BeforeNewEndpointPlugin interface {
	Plugin
	BeforeNewEndpoint(*EndpointConfig, *PluginContainer) error
}

BeforeNewEndpointPlugin 创建Endpoint之前触发该事件

type BeforeReadCallBodyPlugin

type BeforeReadCallBodyPlugin interface {
	Plugin
	BeforeReadCallBody(ReadCtx) *Status
}

BeforeReadCallBodyPlugin 读取CALL消息的body之前触发该事件

type BeforeReadHeaderPlugin

type BeforeReadHeaderPlugin interface {
	Plugin
	BeforeReadHeader(EarlyCtx) error
}

BeforeReadHeaderPlugin 执行读取Header之前触发该事件

type BeforeReadPushBodyPlugin

type BeforeReadPushBodyPlugin interface {
	Plugin
	BeforeReadPushBody(ReadCtx) *Status
}

BeforeReadPushBodyPlugin 读取PUSH消息body之前触发该事件

type BeforeReadReplyBodyPlugin

type BeforeReadReplyBodyPlugin interface {
	Plugin
	BeforeReadReplyBody(ReadCtx) *Status
}

BeforeReadReplyBodyPlugin 读取REPLY消息body之前触发该事件

type BeforeWriteCallPlugin

type BeforeWriteCallPlugin interface {
	Plugin
	BeforeWriteCall(WriteCtx) *Status
}

BeforeWriteCallPlugin 写入CALL消息之前触发该事件

type BeforeWritePushPlugin

type BeforeWritePushPlugin interface {
	Plugin
	BeforeWritePush(WriteCtx) *Status
}

BeforeWritePushPlugin 写入PUSH消息之前触发该事件

type BeforeWriteReplyPlugin

type BeforeWriteReplyPlugin interface {
	Plugin
	BeforeWriteReply(WriteCtx) *Status
}

BeforeWriteReplyPlugin 写入Reply消息之前触发该事件

type CallCmd

type CallCmd interface {
	TraceEndpoint() (e Endpoint, found bool)
	TraceSession() (sess Session, found bool)

	// Context 协程上下文
	Context() context.Context
	// Output 发送的消息
	Output() message.Message

	// StatusOK 状态是否是OK
	StatusOK() bool
	// Status 状态
	Status() *Status
	// Done 返回指示是否已经完毕的chan
	Done() <-chan struct{}
	// Reply 返回应答
	Reply() (interface{}, *Status)

	// InputBodyCodec 接收到的消息使用的编码
	InputBodyCodec() byte
	// InputMeta 接收到的消息传入的元数据
	InputMeta() *gmap.Map
	// CostTime 消耗的时间
	CostTime() time.Duration
}

CallCmd CALL 命令调用后,响应操作的命令

func NewFakeCallCmd added in v0.4.0

func NewFakeCallCmd(serviceMethod string, arg, result interface{}, stat *Status) CallCmd

NewFakeCallCmd 构建伪造的回调命令

type CallCtx

type CallCtx interface {

	// Input 获取传入的消息
	Input() message.Message

	// GetBodyCodec 获取当前消息的编码格式
	GetBodyCodec() byte

	// Output 将要发送的消息对象
	Output() message.Message

	// ReplyBodyCodec 获取响应消息的编码格式
	ReplyBodyCodec() byte

	// SetBodyCodec 设置响应消息的编码格式
	SetBodyCodec(byte)

	// SetMeta 设置指定key的值
	SetMeta(key, value string)

	// AddTFilterId 设置回复消息传输层的编码过滤方法id
	AddTFilterId(filterID ...byte)
	// contains filtered or unexported methods
}

CallCtx call消息使用的上下文

type CtxSession

type CtxSession interface {

	// ID 获取id
	ID() string

	// LocalAddr 本地地址
	LocalAddr() net.Addr

	// RemoteAddr 远端地址
	RemoteAddr() net.Addr

	// Swap 返回交换区的内容
	Swap() *gmap.Map

	// CloseNotify 返回该链接被关闭时候的通知
	CloseNotify() <-chan struct{}

	// Health 检查该session是否健康
	Health() bool

	// AsyncCall 发送消息,并异步接收响应
	AsyncCall(serviceMethod string, args interface{}, result interface{}, callCmdChan chan<- CallCmd, setting ...message.MsgSetting) CallCmd

	// Call 发送消息并获得响应值
	Call(serviceMethod string, args interface{}, result interface{}, setting ...message.MsgSetting) CallCmd

	// Push 发送消息,不接收响应,只返回发送状态
	Push(serviceMethod string, args interface{}, setting ...message.MsgSetting) *status.Status

	// SessionAge 获取session最大的生存周期
	SessionAge() time.Duration

	// ContextAge 获取 CALL 和 PUSH 消息的最大生存周期
	ContextAge() time.Duration
}

CtxSession 在处理程序上下文中传递的会话对象

type Dialer

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

Dialer 拨号器

func NewDialer

func NewDialer(localAddr net.Addr, tlsConfig *tls.Config, dialTimeout, redialInterval time.Duration, redialTimes int) *Dialer

NewDialer 创建一个拨号器

func (*Dialer) Dial

func (that *Dialer) Dial(addr string) (net.Conn, error)

Dial 拨号链接地址 addr

func (*Dialer) DialTimeout

func (that *Dialer) DialTimeout() time.Duration

DialTimeout 获取拨号器拨号时候的超时时间

func (*Dialer) LocalAddr

func (that *Dialer) LocalAddr() net.Addr

LocalAddr 获取拨号器本地使用的端口地址

func (*Dialer) Network

func (that *Dialer) Network() string

Network 获取拨号器的网络类型

func (*Dialer) RedialInterval

func (that *Dialer) RedialInterval() time.Duration

RedialInterval 返回拨号器重试拨号时候的间隔

func (*Dialer) RedialTimes

func (that *Dialer) RedialTimes() int

RedialTimes 拨号器重复拨号的最大次数

func (*Dialer) TLSConfig

func (that *Dialer) TLSConfig() *tls.Config

TLSConfig 获取tls配置信息

type EarlyCtx

type EarlyCtx interface {

	// Endpoint 获取当前Endpoint
	Endpoint() Endpoint

	// Session 返回当前的session
	Session() CtxSession

	// IP 返回远端ip
	IP() string

	// RealIP 返回远端真实ip
	RealIP() string

	// Swap 返回自定义交换区数据
	Swap() *gmap.Map

	// Context 获取上下文
	Context() context.Context
}

EarlyCtx 基础上下文

type EarlyEndpoint

type EarlyEndpoint interface {
	BaseEndpoint

	// Router 获取路由对象
	Router() *Router

	// SubRoute 获取分组路由对象
	SubRoute(pathPrefix string, plugin ...Plugin) *SubRouter

	// RouteCall 通过struct注册CALL类型的处理程序,并且返回注册的路径列表
	RouteCall(ctrlStruct interface{}, plugin ...Plugin) []string
	// RouteCallFunc 通过func注册CALL类型的处理程序,并且返回单个注册路径
	RouteCallFunc(callHandleFunc interface{}, plugin ...Plugin) string
	// RoutePush 通过struct注册PUSH类型的处理程序,并且返回注册的路径列表
	RoutePush(ctrlStruct interface{}, plugin ...Plugin) []string
	// RoutePushFunc 通过func注册PUSH类型的处理程序,并且返回单个注册路径
	RoutePushFunc(pushHandleFunc interface{}, plugin ...Plugin) string
	// SetUnknownCall 设置默认处理程序,当没有找到CALL的处理程序时将调用该处理程序。
	SetUnknownCall(fn func(UnknownCallCtx) (interface{}, *status.Status), plugin ...Plugin)
	// SetUnknownPush 设置默认处理程序,当没有找到PUSH的处理程序时将调用该处理程序。
	SetUnknownPush(fn func(UnknownPushCtx) *status.Status, plugin ...Plugin)
}

type EarlySession

type EarlySession interface {
	Endpoint() Endpoint

	// LocalAddr 本地地址
	LocalAddr() net.Addr

	// RemoteAddr 远端地址
	RemoteAddr() net.Addr

	// Swap 临时存储区内容
	Swap() *gmap.Map

	// SetID 设置session id
	SetID(newID string)

	// ControlFD 原始链接的fd
	ControlFD(f func(fd uintptr)) error

	// ModifySocket 修改session的底层socket
	ModifySocket(fn func(conn net.Conn) (modifiedConn net.Conn, newProtoFunc proto.ProtoFunc))

	// GetProtoFunc 获取协议方法
	GetProtoFunc() proto.ProtoFunc

	// EarlySend 在会话刚建立的时候临时发送消息,不执行任何中间件
	EarlySend(mType byte, serviceMethod string, body interface{}, stat *status.Status, setting ...message.MsgSetting) (opStat *status.Status)

	// EarlyReceive 在会话刚建立的时候临时接受信息,不执行任何中间件
	EarlyReceive(newArgs message.NewBodyFunc, ctx ...context.Context) (input message.Message)

	// EarlyCall 在会话刚建立的时候临时调用call发送和接受消息,不执行任何中间件
	EarlyCall(serviceMethod string, args, reply interface{}, callSetting ...message.MsgSetting) (opStat *status.Status)

	// EarlyReply 在会话刚建立的时候临时回复消息,不执行任何中间件
	EarlyReply(req message.Message, body interface{}, stat *status.Status, setting ...message.MsgSetting) (opStat *status.Status)

	// RawPush 发送原始push消息,不执行任何中间件
	RawPush(serviceMethod string, args interface{}, setting ...message.MsgSetting) (opStat *status.Status)

	// SessionAge 获取session最大的生存周期
	SessionAge() time.Duration

	// ContextAge 获取 CALL 和 PUSH 消息的最大生存周期
	ContextAge() time.Duration

	// SetSessionAge 设置session的最大生存周期
	SetSessionAge(duration time.Duration)

	// SetContextAge 设置单个 CALL 和 PUSH 消息的最大生存周期
	SetContextAge(duration time.Duration)
}

EarlySession 尚未启动 goroutine 读取数据的链接会话

type Endpoint

type Endpoint interface {
	EarlyEndpoint

	// ListenAndServe 打开服务监听
	ListenAndServe(protoFunc ...socket.ProtoFunc) error

	// Dial 作为客户端链接到指定的服务
	Dial(addr string, protoFunc ...socket.ProtoFunc) (Session, *status.Status)

	// ServeConn 传入指定的conn,生成session
	// 提示:
	// 1. 不支持断开链接后自动重拨
	// 2. 不检查TLS
	// 3. 执行 PostAcceptPlugin 插件
	ServeConn(conn net.Conn, protoFunc ...socket.ProtoFunc) (Session, *status.Status)
}

func NewEndpoint

func NewEndpoint(cfg EndpointConfig, globalLeftPlugin ...Plugin) Endpoint

type EndpointConfig

type EndpointConfig struct {

	// 网络类型; tcp, tcp4, tcp6, unix, unixpacket, kcp or quic"
	Network string `json:"network" comment:"网络类型; tcp, tcp4, tcp6, unix, unixpacket"`
	//作为服务端角色时,要监听的服务器本地IP
	ListenIP string `json:"listen_ip" comment:"作为服务端角色时,要监听的服务器本地IP"`
	//作为服务端角色时,需要监听的本地端口号
	ListenPort uint16 `json:"listen_port" comment:"作为服务端角色时,需要监听的本地端口号"`

	//作为客户端角色时,请求服务端时候,本地使用的地址
	LocalIP string `json:"local_ip" comment:"作为客户端角色时,请求服务端时候,本地使用的地址"`
	//作为客户端角色时,请求服务端时候,本地使用的地址端口号
	LocalPort uint16 `json:"local_port" comment:"作为客户端角色时,请求服务端时候,本地使用的地址端口号"`

	// 默认的消息体编码格式
	DefaultBodyCodec string `json:"default_body_codec" comment:"默认的消息体编码格式"`
	//默认session会话生命周期
	DefaultSessionAge time.Duration `json:"default_session_age" comment:"默认session会话生命周期"`
	//默认单次请求生命周期
	DefaultContextAge time.Duration `json:"default_context_age" comment:"默认单次请求生命周期"`
	//外部配置慢处理定义时间
	SlowCometDuration time.Duration `json:"slow_comet_duration" comment:"慢处理定义时长"`

	//是否打印会话中请求的 body或 metadata
	PrintDetail bool `json:"print_detail" comment:"是否打印请求的详细信息,body和metadata"`

	// 作为客户端角色时,请求服务端的超时时间
	DialTimeout time.Duration `json:"dial_timeout" comment:"作为客户端角色时,请求服务端的超时时间"`
	// 仅限客户端角色使用,链接中断时候,试图链接服务端的最大重试次数。
	RedialTimes int `json:"redial_times" comment:"仅限客户端角色使用,链接中断时候,试图链接服务端的最大重试次数。"`
	//仅限客户端角色使用 试图链接服务端时候,重试的时间间隔.
	RedialInterval time.Duration `json:"redial_interval" comment:"仅限客户端角色使用 试图链接服务端时候,重试的时间间隔."`
	// contains filtered or unexported fields
}

EndpointConfig 端点的配置

func (*EndpointConfig) ListenAddr

func (that *EndpointConfig) ListenAddr() net.Addr

ListenAddr 获取本地监听地址,服务器角色

func (*EndpointConfig) LocalAddr

func (that *EndpointConfig) LocalAddr() net.Addr

LocalAddr 获取本地地址,客户端角色

type Handler

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

func (*Handler) ArgElemType

func (that *Handler) ArgElemType() reflect.Type

ArgElemType 参数的类型

func (*Handler) IsCall

func (that *Handler) IsCall() bool

IsCall 处理程序是否是Call

func (*Handler) IsPush

func (that *Handler) IsPush() bool

IsPush 处理程序是否是PUSH

func (*Handler) IsUnknown

func (that *Handler) IsUnknown() bool

IsUnknown 处理程序是否未找到

func (*Handler) Name

func (that *Handler) Name() string

Name 名字

func (*Handler) NewArgValue

func (that *Handler) NewArgValue() reflect.Value

NewArgValue 参数的反射值

func (*Handler) ReplyType

func (that *Handler) ReplyType() reflect.Type

ReplyType 回复消息的类型

func (*Handler) RouterTypeName

func (that *Handler) RouterTypeName() string

RouterTypeName 获取处理器的路由方法名 pnPush/pnCall/pnUnknownPush/pnUnknownCall

type Plugin

type Plugin interface {
	Name() string
}

Plugin 插件的基础对象

type PluginContainer

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

PluginContainer 插件容器

func (*PluginContainer) AppendLeft

func (that *PluginContainer) AppendLeft(plugins ...Plugin)

AppendLeft 追加插件到左边

func (*PluginContainer) AppendRight

func (that *PluginContainer) AppendRight(plugins ...Plugin)

AppendRight 追加插件到右边

func (PluginContainer) GetAll

func (that PluginContainer) GetAll() []Plugin

GetAll 获取所有插件列表

func (PluginContainer) GetByName

func (that PluginContainer) GetByName(pluginName string) Plugin

GetByName 通过插件名字获取插件

func (*PluginContainer) Remove

func (that *PluginContainer) Remove(pluginName string) error

Remove 根据插件名移除插件

type PushCtx

type PushCtx interface {

	// GetBodyCodec 获取当前消息的编码格式
	GetBodyCodec() byte
	// contains filtered or unexported methods
}

PushCtx push消息使用的上下文

type ReadCtx

type ReadCtx interface {

	// Input 获取传入的消息
	Input() message.Message

	// StatusOK 状态是否ok
	StatusOK() bool

	// Status 当前步骤的状态
	Status() *status.Status
	// contains filtered or unexported methods
}

ReadCtx 读取消息使用的上下文

type Router

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

Router 路由器

func (*Router) RouteCall

func (that *Router) RouteCall(callCtrlStruct interface{}, plugin ...Plugin) []string

RouteCall 注册struct对象到路由器

func (*Router) RouteCallFunc

func (that *Router) RouteCallFunc(callHandleFunc interface{}, plugin ...Plugin) string

RouteCallFunc 注册func对象到路由器

func (*Router) RoutePush

func (that *Router) RoutePush(pushCtrlStruct interface{}, plugin ...Plugin) []string

RoutePush 注册 PUSH 类型的处理程序到路由器

func (*Router) RoutePushFunc

func (that *Router) RoutePushFunc(pushHandleFunc interface{}, plugin ...Plugin) string

RoutePushFunc 通过func注册PUSH类型的处理程序到路由器

func (*Router) SetUnknownCall

func (that *Router) SetUnknownCall(fn func(UnknownCallCtx) (interface{}, *status.Status), plugin ...Plugin)

SetUnknownCall 注册默认的未知CALL处理方法

func (*Router) SetUnknownPush

func (that *Router) SetUnknownPush(fn func(UnknownPushCtx) *status.Status, plugin ...Plugin)

SetUnknownPush 注册未知PUSH处理方法

func (*Router) SubRoute

func (that *Router) SubRoute(prefix string, plugin ...Plugin) *SubRouter

SubRoute 添加处理程序组

type ServiceMethodMapper

type ServiceMethodMapper func(prefix, name string) (serviceMethod string)

ServiceMethodMapper ServiceMethod的转换函数类型

type Session

type Session interface {
	Endpoint() Endpoint

	// SetID 设置session id
	SetID(newID string)

	// Close 关闭session
	Close() error

	CtxSession
}

type SessionHub

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

type Status

type Status = status.Status

func NewStatusByCodeText added in v0.4.0

func NewStatusByCodeText(code int32, cause interface{}, tagStack bool) *Status

NewStatusByCodeText 通过错误码生成错误信息

type SubRouter

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

SubRouter 组路由器

func (*SubRouter) Root

func (that *SubRouter) Root() *Router

Root 返回分组路由的根路由器

func (*SubRouter) RouteCall

func (that *SubRouter) RouteCall(callCtrlStruct interface{}, plugin ...Plugin) []string

RouteCall 通过struct注册多个 CALL 类型的处理程序,并返回它们的注册路径

func (*SubRouter) RouteCallFunc

func (that *SubRouter) RouteCallFunc(callHandleFunc interface{}, plugin ...Plugin) string

RouteCallFunc 通过func注册单个 CALL 类型的处理程序,并返回它的注册路径

func (*SubRouter) RoutePush

func (that *SubRouter) RoutePush(pushCtrlStruct interface{}, plugin ...Plugin) []string

RoutePush 通过struct批量注册 PUSH 类型的处理程序,并返回它们的路径

func (*SubRouter) RoutePushFunc

func (that *SubRouter) RoutePushFunc(pushHandleFunc interface{}, plugin ...Plugin) string

RoutePushFunc 通过func注册PUSH类型的处理程序,并返回它的路径

func (*SubRouter) SubRoute

func (that *SubRouter) SubRoute(prefix string, plugin ...Plugin) *SubRouter

SubRoute 添加处理程序组

func (*SubRouter) ToRouter

func (that *SubRouter) ToRouter() *Router

ToRouter 把分组路由转换成根路由

type UnknownCallCtx

type UnknownCallCtx interface {

	// GetBodyCodec 获取当前消息的编码格式
	GetBodyCodec() byte

	// InputBodyBytes 传入消息体
	InputBodyBytes() []byte

	// BuildBody 如果push消息是未知的消息,则使用v对象解析消息内容
	BuildBody(v interface{}) (bodyCodec byte, err error)

	// SetBodyCodec 设置回复消息的编码格式
	SetBodyCodec(byte)

	// SetMeta 设置指定key的值
	SetMeta(key, value string)

	// AddTFilterId 设置回复消息传输层的编码过滤方法id
	AddTFilterId(filterID ...byte)
	// contains filtered or unexported methods
}

UnknownCallCtx 未知call消息的上下文

type UnknownPushCtx

type UnknownPushCtx interface {

	// GetBodyCodec 获取当前消息的编码格式
	GetBodyCodec() byte

	// InputBodyBytes 传入消息体
	InputBodyBytes() []byte

	// BuildBody 如果push消息是未知的消息,则使用v对象解析消息内容
	BuildBody(v interface{}) (bodyCodec byte, err error)
	// contains filtered or unexported methods
}

UnknownPushCtx 未知push消息的上下文

type WriteCtx

type WriteCtx interface {
	EarlyCtx

	// Output 将要发送的消息对象
	Output() message.Message

	// StatusOK 状态是否ok
	StatusOK() bool

	// Status 当前消息状态
	Status() *status.Status
}

WriteCtx 写消息时使用的上下文方法

Directories

Path Synopsis
Package message 消息对象
Package message 消息对象
mixer
websocket/jsonSubProto
Package jsonSubProto 实现JSON套接字通信协议的。
Package jsonSubProto 实现JSON套接字通信协议的。
websocket/pbSubProto
Package pbSubProto 实现PROTOBUF套接字通信协议的。
Package pbSubProto 实现PROTOBUF套接字通信协议的。
netproto
kcp
plugin
ignorecase
Package ignorecase dynamically ignoring the case of path
Package ignorecase dynamically ignoring the case of path

Jump to

Keyboard shortcuts

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