server

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: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Options)

func OptBodyCodec

func OptBodyCodec(c string) Option

OptBodyCodec 设置消息内容编解码器

func OptContextAge

func OptContextAge(n time.Duration) Option

OptContextAge 设置单次请求生命周期

func OptEnableHeartbeat

func OptEnableHeartbeat(t bool) Option

OptEnableHeartbeat 是否开启心跳包

func OptGlobalPlugin

func OptGlobalPlugin(plugin ...drpc.Plugin) Option

OptGlobalPlugin 设置插件

func OptListenAddress

func OptListenAddress(addr string) Option

OptListenAddress 设置监听的网络地址

func OptMetrics added in v1.1.0

func OptMetrics(m metrics.Metrics) Option

OptMetrics 设置统计数据对象

func OptNetwork

func OptNetwork(net string) Option

OptNetwork 设置网络类型

func OptPrintDetail

func OptPrintDetail(c bool) Option

OptPrintDetail 是否打印消息详情

func OptProtoFunc

func OptProtoFunc(pf proto.ProtoFunc) Option

OptProtoFunc 设置协议

func OptRegistry

func OptRegistry(r registry.Registry) Option

OptRegistry 设置服务注册中心

func OptServiceName

func OptServiceName(name string) Option

OptServiceName 设置服务名称

func OptServiceVersion

func OptServiceVersion(version string) Option

OptServiceVersion 当前服务版本

func OptSessionAge

func OptSessionAge(n time.Duration) Option

OptSessionAge 设置会话生命周期

func OptSlowCometDuration

func OptSlowCometDuration(n time.Duration) Option

OptSlowCometDuration 设置慢请求的定义时间

func OptTlsConfig

func OptTlsConfig(config *tls.Config) Option

OptTlsConfig 设置证书对象

func OptTlsFile

func OptTlsFile(tlsCertFile string, tlsKeyFile string) Option

OptTlsFile 设置证书内容

type Options

type Options struct {
	Context           context.Context // 上下文
	ServiceName       string          // 服务名称
	ServiceVersion    string          // 服务版本
	Network           string          // 网络类型
	ListenAddress     string          // 要监听的地址
	TlsCertFile       string
	TlsKeyFile        string
	TLSConfig         *tls.Config
	ProtoFunc         proto.ProtoFunc
	SessionAge        time.Duration
	ContextAge        time.Duration
	SlowCometDuration time.Duration
	BodyCodec         string
	PrintDetail       bool
	Registry          registry.Registry
	GlobalPlugin      []drpc.Plugin
	EnableHeartbeat   bool
	Metrics           metrics.Metrics // 统计信息
}

func (Options) EndpointConfig

func (that Options) EndpointConfig() drpc.EndpointConfig

type RpcServer

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

RpcServer rpc服务端

func NewRpcServer

func NewRpcServer(serviceName string, opt ...Option) *RpcServer

NewRpcServer 创建rpcServer

func (*RpcServer) Close

func (that *RpcServer) Close()

Close 关闭客户端对象

func (*RpcServer) CountSession

func (that *RpcServer) CountSession() int

CountSession 返回回话数量

func (*RpcServer) Endpoint

func (that *RpcServer) Endpoint() drpc.Endpoint

Endpoint 返回Endpoint对象

func (*RpcServer) GetSession

func (that *RpcServer) GetSession(sessionId string) (drpc.Session, bool)

GetSession 通过session id获取session

func (*RpcServer) ListenAndServe

func (that *RpcServer) ListenAndServe(protoFunc ...proto.ProtoFunc) error

ListenAndServe 启动并监听服务

func (*RpcServer) Options

func (that *RpcServer) Options() Options

Options 获取配置信息

func (*RpcServer) RouteCall

func (that *RpcServer) RouteCall(ctrlStruct interface{}, plugin ...drpc.Plugin) []string

RouteCall 通过Struct注册CALL处理方法,返回资源标识符

func (*RpcServer) RouteCallFunc

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

RouteCallFunc 通过func注册CALL处理方法,返回资源标识符

func (*RpcServer) RoutePush

func (that *RpcServer) RoutePush(ctrlStruct interface{}, plugin ...drpc.Plugin) []string

RoutePush 通过Struct注册PUSH处理方法,返回资源标识符

func (*RpcServer) RoutePushFunc

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

RoutePushFunc 通过func注册PUSH处理方法,返回资源标识符

func (*RpcServer) Router

func (that *RpcServer) Router() *drpc.Router

Router 获取路由对象

func (*RpcServer) ServeConn

func (that *RpcServer) ServeConn(conn net.Conn, protoFunc ...proto.ProtoFunc) (drpc.Session, *drpc.Status)

ServeConn 传入指定的conn,生成session 提示: 1. 不支持断开链接后自动重拨 2. 不检查TLS 3. 执行 PostAcceptPlugin 插件

func (*RpcServer) SetUnknownCall

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

SetUnknownCall 设置默认处理方法 当请求call类型的资源标识符不存在时,则执行其设置的方法

func (*RpcServer) SetUnknownPush

func (that *RpcServer) SetUnknownPush(fn func(drpc.UnknownPushCtx) *drpc.Status, plugin ...drpc.Plugin)

SetUnknownPush 设置默认处理方法

当请求push类型的资源标识符不存在时,则执行其设置的方法

func (*RpcServer) SubRoute

func (that *RpcServer) SubRoute(pathPrefix string, plugin ...drpc.Plugin) *drpc.SubRouter

SubRoute 添加分组

Jump to

Keyboard shortcuts

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