Documentation ¶
Index ¶
- Constants
- Variables
- func InstallServerOptionsWatchDog(dog func(cc *ServerOptions))
- func NewService(name string, opt ...ServerOption) app.Service
- type Client
- type ClientContext
- 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 WithHttpServeMux(v *http.ServeMux) ServerOption
- func WithMaxMessageLimit(v int) ServerOption
- func WithNewSession(v func(in Session, r *http.Request) (Session, error)) ServerOption
- func WithProcessOptions(v ...process.ProcessOption) ServerOption
- func WithReadTimeout(v time.Duration) 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 WithUpgrade(v *websocket.Upgrader) ServerOption
- func WithUpgradeFail(v func(w http.ResponseWriter, r *http.Request, reason error)) ServerOption
- func WithWriteMethods(v WriteMethod) ServerOption
- func WithWriteTimeout(v time.Duration) ServerOption
- func WithWsPath(v string) ServerOption
- type ServerOptions
- type Session
- type SessionContext
- type WriteMethod
- type WsServer
- func (s *WsServer) Broadcast(uri interface{}, msg interface{}, md metadata.MD) error
- func (s *WsServer) BroadcastFilter(filter func(Session) bool, uri interface{}, msg interface{}, md metadata.MD) error
- func (s *WsServer) ForEach(f func(Session))
- func (s *WsServer) HttpServeWs(w http.ResponseWriter, r *http.Request)
- func (s *WsServer) Run(addr string) (err error)
- func (s *WsServer) Serve(ln net.Listener) (err error)
- func (s *WsServer) Shutdown(ctx context.Context) (err error)
- type WsService
- type WsSession
- func (sess *WsSession) AddCloseClientFunc(f func(Client))
- func (sess *WsSession) AddCloseSessionFunc(f func(sess Session))
- func (sess *WsSession) ClientValid() bool
- func (sess *WsSession) Close() (err error)
- func (sess *WsSession) GetConn() interface{}
- func (sess *WsSession) GetServer() Server
- func (sess *WsSession) Run()
- func (sess *WsSession) SessionValue(key interface{}) interface{}
- func (sess *WsSession) WithSessionValue(key, value interface{})
- func (sess *WsSession) Write(in []byte) (n int, err error)
Constants ¶
const ( WriteAsync = network.WriteAsync WriteImmediately = network.WriteImmediately )
import const value
Variables ¶
var DefaultUpgrade = &websocket.Upgrader{
ReadBufferSize: 4096,
WriteBufferSize: 4096,
}
var GoServerContextPool process.ContextPool = &goServerContextPool{ Pool: sync.Pool{ New: func() interface{} { return &sessionCtx{} }, }, }
Functions ¶
func InstallServerOptionsWatchDog ¶
func InstallServerOptionsWatchDog(dog func(cc *ServerOptions))
InstallServerOptionsWatchDog install watch dog
func NewService ¶
func NewService(name string, opt ...ServerOption) app.Service
Types ¶
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 WithHttpServeMux ¶
func WithHttpServeMux(v *http.ServeMux) ServerOption
HttpServeMux custom set mux
func WithMaxMessageLimit ¶
func WithMaxMessageLimit(v int) ServerOption
MaxMessageLimit limit message size
func WithNewSession ¶
NewSession custom session
func WithProcessOptions ¶
func WithProcessOptions(v ...process.ProcessOption) ServerOption
Process Options
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 WithUpgradeFail ¶
func WithUpgradeFail(v func(w http.ResponseWriter, r *http.Request, reason error)) ServerOption
SessoinFilter
func WithWriteMethods ¶
func WithWriteMethods(v WriteMethod) ServerOption
Write network data method.
func WithWriteTimeout ¶
func WithWriteTimeout(v time.Duration) ServerOption
WriteTimeout write timeout
type ServerOptions ¶
type ServerOptions struct { // Addr Server Addr Addr string // WsPath websocket server path WsPath string // Upgrade websocket upgrade Upgrade *websocket.Upgrader // SessoinFilter UpgradeFail func(w http.ResponseWriter, r *http.Request, reason error) // 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, r *http.Request) (Session, error) // StopImmediately when session finish,business finish immediately. StopImmediately bool // ReadTimeout read timetou ReadTimeout time.Duration // WriteTimeout write timeout WriteTimeout time.Duration // MaxMessageLimit limit message size MaxMessageLimit int // Write network data method. WriteMethods WriteMethod // SendQueueSize async send queue size SendQueueSize int // Heartbeat use websocket ping/pong. Heartbeat time.Duration // HttpServeMux custom set mux HttpServeMux *http.ServeMux }
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
type WsServer ¶
type WsServer struct {
// contains filtered or unexported fields
}
WsServer websocket server
func NewServer ¶
func NewServer(opts ...ServerOption) *WsServer
func (*WsServer) BroadcastFilter ¶
func (*WsServer) HttpServeWs ¶
func (s *WsServer) HttpServeWs(w http.ResponseWriter, r *http.Request)
serveWs handles websocket requests from the peer.
type WsService ¶
type WsService struct {
// contains filtered or unexported fields
}
WsService implement app.Service interface
type WsSession ¶
type WsSession struct { // process *rpc.RPCProcess // contains filtered or unexported fields }
server session
func NewClientEx ¶
func NewClientEx(addr string, head http.Header, inner *process.InnerOptions, svr *ServerOptions, ) (cli *WsSession, err error)
NewClientEx 创建客户端。NOTE: websocket socket 客户端不支持自动重连.仅用于测试 inner *process.InnerOptions 选项应该由上层ClientProxy去决定如何设置。 svr 内部应该设置链接相关的参数。比如读写超时,如何发送数据 opts 业务方决定
func (*WsSession) AddCloseClientFunc ¶
func (*WsSession) AddCloseSessionFunc ¶
func (*WsSession) ClientValid ¶
func (*WsSession) GetConn ¶
func (sess *WsSession) GetConn() interface{}
GetConn get raw conn(net.Conn,websocket.Conn...)
func (*WsSession) SessionValue ¶
func (sess *WsSession) SessionValue(key interface{}) interface{}
Value wrap context.Context.Value
func (*WsSession) WithSessionValue ¶
func (sess *WsSession) WithSessionValue(key, value interface{})
WithValue wrap context.WithValue