Documentation ¶
Index ¶
- Constants
- func LogDebug(args ...interface{})
- func LogDebugf(format string, args ...interface{})
- func LogError(args ...interface{})
- func LogErrorf(format string, args ...interface{})
- func LogFatal(args ...interface{})
- func LogFatalf(format string, args ...interface{})
- func LogInfo(args ...interface{})
- func LogInfof(format string, args ...interface{})
- func LogWarn(args ...interface{})
- func LogWarnf(format string, args ...interface{})
- func RegisterClientMessageHandler[T any](cli *Client, messageType MessageType, handler func(*T) error)
- func RegisterServerMessageHandler[T any](srv *Server, messageType MessageType, handler func(SessionID, *T) error)
- func SetOperation(ctx context.Context, op string)
- type Any
- type BinaryMessage
- type Binder
- type Client
- func (c *Client) Connect() error
- func (c *Client) DeregisterMessageHandler(messageType MessageType)
- func (c *Client) Disconnect()
- func (c *Client) RegisterMessageHandler(messageType MessageType, handler ClientMessageHandler, binder Binder)
- func (c *Client) SendMessage(messageType MessageType, message interface{}) error
- type ClientHandlerData
- type ClientMessageHandler
- type ClientMessageHandlerMap
- type ClientOption
- type ConnectHandler
- type HandlerData
- type MessageHandler
- type MessageHandlerMap
- type MessagePayload
- type MessageType
- type PayloadType
- type Server
- func (s *Server) Broadcast(messageType MessageType, message MessagePayload)
- func (s *Server) DeregisterMessageHandler(messageType MessageType)
- func (s *Server) Endpoint() (*url.URL, error)
- func (s *Server) Name() string
- func (s *Server) RegisterMessageHandler(messageType MessageType, handler MessageHandler, binder Binder)
- func (s *Server) SendMessage(sessionId SessionID, messageType MessageType, message MessagePayload)
- func (s *Server) SessionCount() int
- func (s *Server) Start(ctx context.Context) error
- func (s *Server) Stop(ctx context.Context) error
- type ServerOption
- func WithAddress(addr string) ServerOption
- func WithChannelBufferSize(size int) ServerOption
- func WithCodec(c string) ServerOption
- func WithConnectHandle(h ConnectHandler) ServerOption
- func WithInjectTokenToQuery(enable bool, tokenKey string) ServerOption
- func WithListener(lis net.Listener) ServerOption
- func WithNetwork(network string) ServerOption
- func WithPath(path string) ServerOption
- func WithPayloadType(payloadType PayloadType) ServerOption
- func WithTLSConfig(c *tls.Config) ServerOption
- func WithTimeout(timeout time.Duration) ServerOption
- type Session
- type SessionID
- type SessionManager
- func (s *SessionManager) Add(session *Session)
- func (s *SessionManager) Clean()
- func (s *SessionManager) Count() int
- func (s *SessionManager) Get(sessionId SessionID) (*Session, bool)
- func (s *SessionManager) Range(fn func(*Session))
- func (s *SessionManager) RegisterConnectHandler(handler ConnectHandler)
- func (s *SessionManager) Remove(session *Session)
- type SessionMap
- type TextMessage
- type Transport
- func (tr *Transport) Endpoint() string
- func (tr *Transport) Kind() kratosTransport.Kind
- func (tr *Transport) Operation() string
- func (tr *Transport) PathTemplate() string
- func (tr *Transport) ReplyHeader() kratosTransport.Header
- func (tr *Transport) Request() *http.Request
- func (tr *Transport) RequestHeader() kratosTransport.Header
- type Transporter
Constants ¶
View Source
const ( PayloadTypeBinary = 0 PayloadTypeText = 1 )
View Source
const (
KindWebsocket kratosTransport.Kind = "websocket"
)
Variables ¶
This section is empty.
Functions ¶
func RegisterClientMessageHandler ¶
func RegisterClientMessageHandler[T any](cli *Client, messageType MessageType, handler func(*T) error)
func RegisterServerMessageHandler ¶
func RegisterServerMessageHandler[T any](srv *Server, messageType MessageType, handler func(SessionID, *T) error)
func SetOperation ¶
SetOperation sets the transport operation.
Types ¶
type BinaryMessage ¶
type BinaryMessage struct { Type MessageType Body []byte }
func (*BinaryMessage) Marshal ¶
func (m *BinaryMessage) Marshal() ([]byte, error)
func (*BinaryMessage) Unmarshal ¶
func (m *BinaryMessage) Unmarshal(buf []byte) error
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(opts ...ClientOption) *Client
func (*Client) DeregisterMessageHandler ¶
func (c *Client) DeregisterMessageHandler(messageType MessageType)
func (*Client) Disconnect ¶
func (c *Client) Disconnect()
func (*Client) RegisterMessageHandler ¶
func (c *Client) RegisterMessageHandler(messageType MessageType, handler ClientMessageHandler, binder Binder)
func (*Client) SendMessage ¶
func (c *Client) SendMessage(messageType MessageType, message interface{}) error
type ClientHandlerData ¶
type ClientHandlerData struct { Handler ClientMessageHandler Binder Binder }
type ClientMessageHandler ¶
type ClientMessageHandler func(MessagePayload) error
type ClientMessageHandlerMap ¶
type ClientMessageHandlerMap map[MessageType]*ClientHandlerData
type ClientOption ¶
type ClientOption func(o *Client)
func WithClientCodec ¶
func WithClientCodec(c string) ClientOption
func WithClientPayloadType ¶
func WithClientPayloadType(payloadType PayloadType) ClientOption
func WithEndpoint ¶
func WithEndpoint(uri string) ClientOption
type ConnectHandler ¶
type HandlerData ¶
type HandlerData struct { Handler MessageHandler Binder Binder }
type MessageHandler ¶
type MessageHandler func(SessionID, MessagePayload) error
type MessageHandlerMap ¶
type MessageHandlerMap map[MessageType]*HandlerData
type MessagePayload ¶
type MessagePayload Any
type MessageType ¶
type MessageType uint32
type PayloadType ¶
type PayloadType uint8
type Server ¶
func NewServer ¶
func NewServer(opts ...ServerOption) *Server
func (*Server) Broadcast ¶
func (s *Server) Broadcast(messageType MessageType, message MessagePayload)
func (*Server) DeregisterMessageHandler ¶
func (s *Server) DeregisterMessageHandler(messageType MessageType)
func (*Server) RegisterMessageHandler ¶
func (s *Server) RegisterMessageHandler(messageType MessageType, handler MessageHandler, binder Binder)
func (*Server) SendMessage ¶
func (s *Server) SendMessage(sessionId SessionID, messageType MessageType, message MessagePayload)
func (*Server) SessionCount ¶
type ServerOption ¶
type ServerOption func(o *Server)
func WithAddress ¶
func WithAddress(addr string) ServerOption
func WithChannelBufferSize ¶
func WithChannelBufferSize(size int) ServerOption
func WithCodec ¶
func WithCodec(c string) ServerOption
func WithConnectHandle ¶
func WithConnectHandle(h ConnectHandler) ServerOption
func WithInjectTokenToQuery ¶ added in v1.2.17
func WithInjectTokenToQuery(enable bool, tokenKey string) ServerOption
func WithListener ¶
func WithListener(lis net.Listener) ServerOption
func WithNetwork ¶
func WithNetwork(network string) ServerOption
func WithPath ¶
func WithPath(path string) ServerOption
func WithPayloadType ¶
func WithPayloadType(payloadType PayloadType) ServerOption
func WithTLSConfig ¶
func WithTLSConfig(c *tls.Config) ServerOption
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ServerOption
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func (*Session) SendMessage ¶
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
func NewSessionManager ¶
func NewSessionManager() *SessionManager
func (*SessionManager) Add ¶
func (s *SessionManager) Add(session *Session)
func (*SessionManager) Clean ¶
func (s *SessionManager) Clean()
func (*SessionManager) Count ¶
func (s *SessionManager) Count() int
func (*SessionManager) Range ¶
func (s *SessionManager) Range(fn func(*Session))
func (*SessionManager) RegisterConnectHandler ¶
func (s *SessionManager) RegisterConnectHandler(handler ConnectHandler)
func (*SessionManager) Remove ¶
func (s *SessionManager) Remove(session *Session)
type SessionMap ¶
type TextMessage ¶
type TextMessage struct { Type MessageType `json:"type" xml:"type"` Body string `json:"body" xml:"body"` }
func (*TextMessage) Marshal ¶
func (m *TextMessage) Marshal() ([]byte, error)
func (*TextMessage) Unmarshal ¶
func (m *TextMessage) Unmarshal(buf []byte) error
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is a websocket transport.
func (*Transport) Kind ¶
func (tr *Transport) Kind() kratosTransport.Kind
Kind returns the transport kind.
func (*Transport) PathTemplate ¶
PathTemplate returns the http path template.
func (*Transport) ReplyHeader ¶
func (tr *Transport) ReplyHeader() kratosTransport.Header
ReplyHeader returns the reply header.
func (*Transport) RequestHeader ¶
func (tr *Transport) RequestHeader() kratosTransport.Header
RequestHeader returns the request header.
type Transporter ¶
type Transporter interface { kratosTransport.Transporter Request() *http.Request PathTemplate() string }
Click to show internal directories.
Click to hide internal directories.