Documentation ¶
Index ¶
- Constants
- Variables
- func InstallClientOptionsWatchDog(dog func(cc *ClientOptions))
- func InstallServerOptionsWatchDog(dog func(cc *ServerOptions))
- func NewService(name string, opt ...ServerOption) app.Service
- type Client
- type ClientContext
- type ClientOption
- func WithClientOptionAddr(v string) ClientOption
- func WithClientOptionAutoReconnectTime(v int) ClientOption
- func WithClientOptionAutoReconnectWait(v time.Duration) ClientOption
- func WithClientOptionBlockConnect(v bool) ClientOption
- func WithClientOptionDialer(v func(network, addr string) (conn net.Conn, err error)) ClientOption
- func WithClientOptionFrameLogger(v *zaplog.Logger) ClientOption
- func WithClientOptionHeartbeat(v time.Duration) ClientOption
- func WithClientOptionMaxMessageSizeLimit(v int) ClientOption
- func WithClientOptionNetwork(v string) ClientOption
- func WithClientOptionPacketHeadBuf(v func() []byte) ClientOption
- func WithClientOptionProcessOptions(v ...process.ProcessOption) ClientOption
- func WithClientOptionReadBufferSize(v int) ClientOption
- func WithClientOptionReadSize(v func(head []byte) (size int)) ClientOption
- func WithClientOptionReadTimeout(v time.Duration) ClientOption
- func WithClientOptionReuseReadBuffer(v bool) ClientOption
- func WithClientOptionRouter(v Router) ClientOption
- func WithClientOptionSendQueueSize(v int) ClientOption
- func WithClientOptionStopImmediately(v bool) ClientOption
- func WithClientOptionWriteMethods(v WriteMethod) ClientOption
- func WithClientOptionWriteSize(v func(head []byte, size int) (err error)) ClientOption
- func WithClientOptionWriteTimeout(v time.Duration) ClientOption
- type ClientOptions
- type GoClient
- func (sess *GoClient) AddCloseClientFunc(f func(sess Client))
- func (sess *GoClient) ClientValid() bool
- func (sess *GoClient) Close() (err error)
- func (sess *GoClient) GetConn() interface{}
- func (sess *GoClient) Run()
- func (sess *GoClient) SessionValue(key interface{}) interface{}
- func (sess *GoClient) WithSessionValue(key, value interface{})
- func (sess *GoClient) Write(in []byte) (n int, err error)
- type GoServer
- func (s *GoServer) Broadcast(uri interface{}, msg interface{}, md metadata.MD) error
- func (s *GoServer) BroadcastFilter(filter func(Session) bool, uri interface{}, msg interface{}, md metadata.MD) error
- func (s *GoServer) ForEach(f func(Session))
- func (s *GoServer) Listen(addr string) (err error)
- func (s *GoServer) Run(addr string) (err error)
- func (s *GoServer) Serve(ln net.Listener) (err error)
- func (s *GoServer) Shutdown(ctx context.Context) (err error)
- type GoSession
- func (sess *GoSession) AddCloseSessionFunc(f func(sess Session))
- func (sess *GoSession) Close() (err error)
- func (sess *GoSession) GetConn() interface{}
- func (sess *GoSession) GetServer() Server
- func (sess *GoSession) Run()
- func (sess *GoSession) SessionValue(key interface{}) interface{}
- func (sess *GoSession) WithSessionValue(key, value interface{})
- func (sess *GoSession) Write(in []byte) (n int, err error)
- type GoTcpService
- type Router
- type Server
- type ServerOption
- func WithAcceptLoadLimit(v func(sess Session, cnt int64) bool) ServerOption
- func WithAddr(v string) ServerOption
- func WithFrameLogger(v *zaplog.Logger) ServerOption
- func WithHeartbeat(v time.Duration) ServerOption
- func WithListen(v func(addr string) (ln net.Listener, err error)) ServerOption
- func WithMaxMessageSizeLimit(v int) ServerOption
- func WithNetConnOption(v func(net.Conn)) ServerOption
- func WithNewSession(v func(in Session) (Session, error)) ServerOption
- func WithPacketHeadBuf(v func() []byte) ServerOption
- func WithProcessOptions(v ...process.ProcessOption) ServerOption
- func WithReadBufferSize(v int) ServerOption
- func WithReadSize(v func(head []byte) (size int)) ServerOption
- func WithReadTimeout(v time.Duration) ServerOption
- func WithRegistry(v discovery.Registry) ServerOption
- func WithReuseReadBuffer(v bool) ServerOption
- func WithRouter(v Router) ServerOption
- func WithSendQueueSize(v int) ServerOption
- func WithSessionLogger(v func(sess Session, global *zaplog.Logger) (r *zaplog.Logger)) ServerOption
- func WithSessionRouter(v func(sess Session, global Router) (r Router)) ServerOption
- func WithStopImmediately(v bool) ServerOption
- func WithWriteMethods(v WriteMethod) ServerOption
- func WithWriteSize(v func(head []byte, size int) (err error)) ServerOption
- func WithWriteTimeout(v time.Duration) ServerOption
- type ServerOptions
- type Session
- type SessionContext
- type WriteMethod
Constants ¶
const ( WriteAsync = network.WriteAsync WriteImmediately = network.WriteImmediately )
import const value
Variables ¶
var GoClientContextPool process.ContextPool = &goClientContextPool{ Pool: sync.Pool{ New: func() interface{} { return &clientCtx{} }, }, }
var GoServerContextPool process.ContextPool = &goServerContextPool{ Pool: sync.Pool{ New: func() interface{} { return &sessionCtx{} }, }, }
Functions ¶
func InstallClientOptionsWatchDog ¶
func InstallClientOptionsWatchDog(dog func(cc *ClientOptions))
InstallClientOptionsWatchDog install watch dog
func InstallServerOptionsWatchDog ¶
func InstallServerOptionsWatchDog(dog func(cc *ServerOptions))
InstallServerOptionsWatchDog install watch dog
func NewService ¶
func NewService(name string, opt ...ServerOption) app.Service
Types ¶
type Client ¶
import type
func NewClient ¶
func NewClient(opts ...ClientOption) (_ Client, err error)
func NewClientForProxy ¶
func NewClientForProxy(net, addr string, inner *process.InnerOptions) (Client, error)
NewClientForProxy new client for client proxy. NOTE: you should rewrite this function for custom set option
type ClientOption ¶
type ClientOption func(cc *ClientOptions) ClientOption
ClientOption option define
func WithClientOptionAutoReconnectTime ¶
func WithClientOptionAutoReconnectTime(v int) ClientOption
AutoReconnect auto reconnect server. zero means not reconnect! -1 means always reconnect, >0 : reconnect times
func WithClientOptionAutoReconnectWait ¶
func WithClientOptionAutoReconnectWait(v time.Duration) ClientOption
AutoReconnectWait reconnect wait time
func WithClientOptionBlockConnect ¶
func WithClientOptionBlockConnect(v bool) ClientOption
BlockConnect 创建客户端时候,是否阻塞等待链接服务器
func WithClientOptionDialer ¶
func WithClientOptionDialer(v func(network, addr string) (conn net.Conn, err error)) ClientOption
Dialer config net dialer
func WithClientOptionFrameLogger ¶
func WithClientOptionFrameLogger(v *zaplog.Logger) ClientOption
frame log
func WithClientOptionHeartbeat ¶
func WithClientOptionHeartbeat(v time.Duration) ClientOption
Heartbeat use websocket ping/pong.
func WithClientOptionMaxMessageSizeLimit ¶
func WithClientOptionMaxMessageSizeLimit(v int) ClientOption
MaxMessageSizeLimit limit message size
func WithClientOptionNetwork ¶
func WithClientOptionNetwork(v string) ClientOption
Network tcp/tcp4/tcp6/unix
func WithClientOptionPacketHeadBuf ¶
func WithClientOptionPacketHeadBuf(v func() []byte) ClientOption
tcp packet head
func WithClientOptionProcessOptions ¶
func WithClientOptionProcessOptions(v ...process.ProcessOption) ClientOption
Process Options
func WithClientOptionReadBufferSize ¶
func WithClientOptionReadBufferSize(v int) ClientOption
ReadBufferSize 一定要大于最大消息的大小.每个链接一个缓冲区。
func WithClientOptionReadSize ¶
func WithClientOptionReadSize(v func(head []byte) (size int)) ClientOption
read tcp packet head size
func WithClientOptionReadTimeout ¶
func WithClientOptionReadTimeout(v time.Duration) ClientOption
ReadTimeout read timeout
func WithClientOptionReuseReadBuffer ¶
func WithClientOptionReuseReadBuffer(v bool) ClientOption
ReuseReadBuffer 复用read缓存区。影响Process.DispatchFilter. 如果此选项设置为true,在DispatchFilter内如果开启协程,需要手动复制内存。 如果在DispatchFilter内不开启协程,设置为true可以减少内存分配。
func WithClientOptionSendQueueSize ¶
func WithClientOptionSendQueueSize(v int) ClientOption
SendQueueSize async send queue size
func WithClientOptionStopImmediately ¶
func WithClientOptionStopImmediately(v bool) ClientOption
StopImmediately when session finish,business finish immediately.
func WithClientOptionWriteMethods ¶
func WithClientOptionWriteMethods(v WriteMethod) ClientOption
Write network data method.
func WithClientOptionWriteSize ¶
func WithClientOptionWriteSize(v func(head []byte, size int) (err error)) ClientOption
write tcp packet head size
func WithClientOptionWriteTimeout ¶
func WithClientOptionWriteTimeout(v time.Duration) ClientOption
WriteTimeout write timeout
type ClientOptions ¶
type ClientOptions struct { // Network tcp/tcp4/tcp6/unix Network string // Addr Server Addr Addr string // Dialer config net dialer Dialer func(network, addr string) (conn net.Conn, err error) // Process Options ProcessOptions []process.ProcessOption // process router Router Router // frame log FrameLogger *zaplog.Logger // AutoReconnect auto reconnect server. zero means not reconnect! -1 means always reconnect, >0 : reconnect times AutoReconnectTime int // AutoReconnectWait reconnect wait time AutoReconnectWait time.Duration // StopImmediately when session finish,business finish immediately. StopImmediately bool // ReadTimeout read timeout ReadTimeout time.Duration // WriteTimeout write timeout WriteTimeout time.Duration // Write network data method. WriteMethods WriteMethod // SendQueueSize async send queue size SendQueueSize int // Heartbeat use websocket ping/pong. Heartbeat time.Duration // tcp packet head PacketHeadBuf func() []byte // read tcp packet head size ReadSize func(head []byte) (size int) // write tcp packet head size WriteSize func(head []byte, size int) (err error) // ReadBufferSize 一定要大于最大消息的大小.每个链接一个缓冲区。 ReadBufferSize int // ReuseReadBuffer 复用read缓存区。影响Process.DispatchFilter. // 如果此选项设置为true,在DispatchFilter内如果开启协程,需要手动复制内存。 // 如果在DispatchFilter内不开启协程,设置为true可以减少内存分配。 ReuseReadBuffer bool // MaxMessageSizeLimit limit message size MaxMessageSizeLimit int // BlockConnect 创建客户端时候,是否阻塞等待链接服务器 BlockConnect bool }
ClientOption
func NewClientOptions ¶
func NewClientOptions(opts ...ClientOption) *ClientOptions
NewClientOptions create options instance.
func (*ClientOptions) ApplyOption ¶
func (cc *ClientOptions) ApplyOption(opts ...ClientOption)
ApplyOption modify options
func (*ClientOptions) GetSetOption ¶
func (cc *ClientOptions) GetSetOption(opt ClientOption) ClientOption
GetSetOption modify and get last option
func (*ClientOptions) SetOption ¶
func (cc *ClientOptions) SetOption(opt ClientOption)
SetOption modify options
type GoClient ¶
type GoClient struct { // process *rpc.RPCProcess // contains filtered or unexported fields }
go client
func NewClientEx ¶
func NewClientEx(inner *process.InnerOptions, copts *ClientOptions) (cli *GoClient, err error)
NewClientEx 创建客户端 inner *process.InnerOptions 选项应该由上层ClientProxy去决定如何设置。 copts 内部应该设置链接相关的参数。比如读写超时,如何发送数据 opts 业务方决定
func (*GoClient) AddCloseClientFunc ¶
func (*GoClient) ClientValid ¶
func (*GoClient) GetConn ¶
func (sess *GoClient) GetConn() interface{}
GetConn get raw conn(net.Conn,websocket.Conn...)
func (*GoClient) SessionValue ¶
func (sess *GoClient) SessionValue(key interface{}) interface{}
Value wrap context.Context.Value
func (*GoClient) WithSessionValue ¶
func (sess *GoClient) WithSessionValue(key, value interface{})
WithValue wrap context.WithValue
type GoServer ¶
type GoServer struct {
// contains filtered or unexported fields
}
GoServer websocket server
func NewServer ¶
func NewServer(opts ...ServerOption) *GoServer
func (*GoServer) BroadcastFilter ¶
type GoSession ¶
type GoSession struct { // process *rpc.RPCProcess // contains filtered or unexported fields }
server session
func (*GoSession) AddCloseSessionFunc ¶
func (*GoSession) GetConn ¶
func (sess *GoSession) GetConn() interface{}
GetConn get raw conn(net.Conn,websocket.Conn...)
func (*GoSession) SessionValue ¶
func (sess *GoSession) SessionValue(key interface{}) interface{}
Value wrap context.Context.Value
func (*GoSession) WithSessionValue ¶
func (sess *GoSession) WithSessionValue(key, value interface{})
WithValue wrap context.WithValue
type GoTcpService ¶
type GoTcpService struct {
// contains filtered or unexported fields
}
GoTcpService implement app.Service interface
func (*GoTcpService) Finish ¶
func (svc *GoTcpService) Finish()
func (*GoTcpService) Name ¶
func (svc *GoTcpService) Name() string
func (*GoTcpService) Stop ¶
func (svc *GoTcpService) Stop()
type ServerOption ¶
type ServerOption func(cc *ServerOptions) ServerOption
ServerOption option define
func WithAcceptLoadLimit ¶
func WithAcceptLoadLimit(v func(sess Session, cnt int64) bool) ServerOption
accepted load limit
func WithHeartbeat ¶
func WithHeartbeat(v time.Duration) ServerOption
Heartbeat use websocket ping/pong.
func WithListen ¶
func WithListen(v func(addr string) (ln net.Listener, err error)) ServerOption
Listen option. can replace kcp wrap
func WithMaxMessageSizeLimit ¶
func WithMaxMessageSizeLimit(v int) ServerOption
MaxMessageSizeLimit limit message size
func WithNetConnOption ¶
func WithNetConnOption(v func(net.Conn)) ServerOption
NetOption modify raw options
func WithNewSession ¶
func WithNewSession(v func(in Session) (Session, error)) ServerOption
NewSession custom session
func WithProcessOptions ¶
func WithProcessOptions(v ...process.ProcessOption) ServerOption
Process Options
func WithReadBufferSize ¶
func WithReadBufferSize(v int) ServerOption
ReadBufferSize 一定要大于最大消息的大小.每个链接一个缓冲区。
func WithReadSize ¶
func WithReadSize(v func(head []byte) (size int)) ServerOption
read tcp packet head size
func WithReuseReadBuffer ¶
func WithReuseReadBuffer(v bool) ServerOption
ReuseReadBuffer 复用read缓存区。影响Process.DispatchFilter. 如果此选项设置为true,在DispatchFilter内如果开启协程,需要手动复制内存。 如果在DispatchFilter内不开启协程,设置为true可以减少内存分配。 默认为false,是为了防止错误的配置导致bug。
func WithSendQueueSize ¶
func WithSendQueueSize(v int) ServerOption
SendQueueSize async send queue size
func WithSessionLogger ¶
SessionLogger custom session logger
func WithSessionRouter ¶
func WithSessionRouter(v func(sess Session, global Router) (r Router)) ServerOption
SessionRouter custom session router
func WithStopImmediately ¶
func WithStopImmediately(v bool) ServerOption
StopImmediately when session finish,business finish immediately.
func WithWriteMethods ¶
func WithWriteMethods(v WriteMethod) ServerOption
Write network data method.
func WithWriteSize ¶
func WithWriteSize(v func(head []byte, size int) (err error)) ServerOption
write tcp packet head size
func WithWriteTimeout ¶
func WithWriteTimeout(v time.Duration) ServerOption
WriteTimeout write timeout
type ServerOptions ¶
type ServerOptions struct { // Addr Server Addr Addr string // Listen option. can replace kcp wrap Listen func(addr string) (ln net.Listener, err error) // NetOption modify raw options NetConnOption func(net.Conn) // accepted load limit AcceptLoadLimit func(sess Session, cnt int64) bool // Process Options ProcessOptions []process.ProcessOption // process router Router Router // SessionRouter custom session router SessionRouter func(sess Session, global Router) (r Router) // frame log FrameLogger *zaplog.Logger // SessionLogger custom session logger SessionLogger func(sess Session, global *zaplog.Logger) (r *zaplog.Logger) // NewSession custom session NewSession func(in Session) (Session, error) // StopImmediately when session finish,business finish immediately. StopImmediately bool // ReadTimeout read timetou ReadTimeout time.Duration // WriteTimeout write timeout WriteTimeout time.Duration // Write network data method. WriteMethods WriteMethod // SendQueueSize async send queue size SendQueueSize int // Heartbeat use websocket ping/pong. Heartbeat time.Duration // tcp packet head PacketHeadBuf func() []byte // read tcp packet head size ReadSize func(head []byte) (size int) // write tcp packet head size WriteSize func(head []byte, size int) (err error) // ReadBufferSize 一定要大于最大消息的大小.每个链接一个缓冲区。 ReadBufferSize int // ReuseReadBuffer 复用read缓存区。影响Process.DispatchFilter. // 如果此选项设置为true,在DispatchFilter内如果开启协程,需要手动复制内存。 // 如果在DispatchFilter内不开启协程,设置为true可以减少内存分配。 // 默认为false,是为了防止错误的配置导致bug。 ReuseReadBuffer bool // MaxMessageSizeLimit limit message size MaxMessageSizeLimit int // Registry Registry discovery.Registry }
ServerOption
func NewServerOptions ¶
func NewServerOptions(opts ...ServerOption) *ServerOptions
NewServerOptions create options instance.
func (*ServerOptions) ApplyOption ¶
func (cc *ServerOptions) ApplyOption(opts ...ServerOption)
ApplyOption modify options
func (*ServerOptions) GetSetOption ¶
func (cc *ServerOptions) GetSetOption(opt ServerOption) ServerOption
GetSetOption modify and get last option
func (*ServerOptions) SetOption ¶
func (cc *ServerOptions) SetOption(opt ServerOption)
SetOption modify options