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)
- func WithBigEndian()
- func WithLittleEndian()
- type Any
- 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 int, message interface{}) error
- func (c *Client) SendRawData(message []byte) error
- type ClientHandlerData
- type ClientMessageHandler
- type ClientMessageHandlerMap
- type ClientOption
- type ClientRawMessageHandler
- type ConnectHandler
- type HandlerData
- type Message
- type MessageHandler
- type MessageHandlerMap
- type MessagePayload
- type MessageType
- type RawMessageHandler
- type Server
- func (s *Server) Broadcast(messageType MessageType, message MessagePayload)
- func (s *Server) BroadcastRawData(message []byte)
- func (s *Server) DeregisterMessageHandler(messageType MessageType)
- func (s *Server) Endpoint() (*url.URL, error)
- func (s *Server) GetMessageHandler(msgType MessageType) (error, *HandlerData)
- func (s *Server) HandleMessage(sessionId SessionID, msgType MessageType, msgBody []byte) 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) error
- func (s *Server) SendRawData(sessionId SessionID, message []byte) error
- func (s *Server) SessionCount() int
- func (s *Server) Start(_ context.Context) error
- func (s *Server) Stop(_ context.Context) error
- type ServerOption
- func WithAddress(addr string) ServerOption
- func WithChannelBufferSize(size int) ServerOption
- func WithCodec(c string) ServerOption
- func WithConnectHandler(h ConnectHandler) ServerOption
- func WithRawDataHandler(h RawMessageHandler) ServerOption
- func WithRecvBufferSize(size int) ServerOption
- func WithTLSConfig(c *tls.Config) ServerOption
- func WithTimeout(timeout time.Duration) ServerOption
- type Session
- type SessionID
- type SessionMap
- 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 (
KindTcp kratosTransport.Kind = "tcp"
)
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 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 (*Client) SendRawData ¶
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(codec string) ClientOption
func WithClientRawDataHandler ¶
func WithClientRawDataHandler(h ClientRawMessageHandler) ClientOption
func WithEndpoint ¶
func WithEndpoint(uri string) ClientOption
type ClientRawMessageHandler ¶
type ConnectHandler ¶
type HandlerData ¶
type HandlerData struct { Handler MessageHandler Binder Binder }
type Message ¶
type Message struct { Type MessageType Body []byte }
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 RawMessageHandler ¶
type RawMessageHandler func(SessionID, []byte) (err error, msgType MessageType, msgBody []byte)
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(opts ...ServerOption) *Server
func (*Server) Broadcast ¶
func (s *Server) Broadcast(messageType MessageType, message MessagePayload)
func (*Server) BroadcastRawData ¶
func (*Server) DeregisterMessageHandler ¶
func (s *Server) DeregisterMessageHandler(messageType MessageType)
func (*Server) GetMessageHandler ¶ added in v1.2.12
func (s *Server) GetMessageHandler(msgType MessageType) (error, *HandlerData)
GetMessageHandler find message handler
func (*Server) HandleMessage ¶ added in v1.2.12
func (s *Server) HandleMessage(sessionId SessionID, msgType MessageType, msgBody []byte) error
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) error
func (*Server) SendRawData ¶
SendRawData send raw data to client
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 WithConnectHandler ¶
func WithConnectHandler(h ConnectHandler) ServerOption
func WithRawDataHandler ¶
func WithRawDataHandler(h RawMessageHandler) ServerOption
func WithRecvBufferSize ¶
func WithRecvBufferSize(size int) 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 SessionMap ¶
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is a tcp 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.