Documentation ¶
Index ¶
- Constants
- Variables
- func ReadPacket(r io.Reader) ([]byte, error)
- type ChannelConfig
- type ChannelContext
- type ChannelState
- type Client
- type ClientConfig
- type Code
- type Command
- func (cmd *Command) Decode(buf []byte) (interface{}, error)
- func (cmd *Command) Encode(interface{}) ([]byte, error)
- func (cmd *Command) ID() int64
- func (cmd *Command) IsOneway() bool
- func (cmd *Command) MarkResponse()
- func (cmd *Command) Read(r io.Reader) ([]byte, error)
- func (cmd *Command) String() string
- type Decoder
- type DecoderFunc
- type Encoder
- type EncoderFunc
- type FakeClient
- func (m *FakeClient) RequestAsync(addr string, cmd *Command, timeout time.Duration, ...) error
- func (m *FakeClient) RequestOneway(addr string, cmd *Command) error
- func (m *FakeClient) RequestSync(addr string, cmd *Command, timeout time.Duration) (*Command, error)
- func (m *FakeClient) Shutdown()
- func (m *FakeClient) Start() error
- type Handler
- type HeaderOfMapper
- type LanguageCode
- type PacketReader
- type PacketReaderFunc
Constants ¶
const ( // StateDisconnected disconnected status StateDisconnected int32 = iota // StateConnected connected status StateConnected // StateClosing closing status StateClosing )
const ( // ProtoJSON json codec ProtoJSON = iota // ProtoRocketMQ rocket mq codec ProtoRocketMQ )
Variables ¶
var ErrBadContent = errors.New("bad content")
ErrBadContent indicate the data is not recognized
var ErrDisconnected = errors.New("disconnected")
ErrDisconnected disconnected error
var ErrNeedContent = errors.New("need content")
ErrNeedContent indicate need to read data
Functions ¶
Types ¶
type ChannelConfig ¶
type ChannelConfig struct { ClientConfig Encoder PacketReader Decoder Handler // contains filtered or unexported fields }
ChannelConfig contains channel's configuration
type ChannelContext ¶
ChannelContext channel's context
func (*ChannelContext) String ¶
func (ctx *ChannelContext) String() string
type Client ¶
type Client interface { RequestSync(addr string, cmd *Command, timeout time.Duration) (*Command, error) RequestAsync(addr string, cmd *Command, timeout time.Duration, callback func(*Command, error)) error RequestOneway(addr string, cmd *Command) error Start() error Shutdown() }
Client exchange the message with server
func NewClient ¶
func NewClient( conf ClientConfig, rp func(*ChannelContext, *Command) bool, logger log.Logger, ) ( Client, error, )
NewClient create the client
type ClientConfig ¶
type ClientConfig struct { ReadTimeout time.Duration WriteTimeout time.Duration DialTimeout time.Duration }
ClientConfig timeout configuration
type Code ¶
type Code int16
Code command code
func (*Code) UnmarshalJSON ¶
UnmarshalJSON unmarshal code
type Command ¶
type Command struct { Code Code `json:"code"` Language LanguageCode `json:"language"` Version int16 `json:"version"` Opaque int32 `json:"opaque"` Flag int32 `json:"flag"` Remark string `json:"remark"` ExtFields map[string]string `json:"extFields"` Body []byte `json:"body,-"` }
Command remoting command
func NewCommand ¶
func NewCommand(code Code, header HeaderOfMapper) *Command
NewCommand create command with empty body
func NewCommandWithBody ¶
func NewCommandWithBody(code Code, header HeaderOfMapper, body []byte) *Command
NewCommandWithBody with body
func (*Command) MarkResponse ¶
func (cmd *Command) MarkResponse()
MarkResponse mark the command as response
type DecoderFunc ¶
DecoderFunc decoder function
type EncoderFunc ¶
EncoderFunc encoder function
type FakeClient ¶
type FakeClient struct { }
func (*FakeClient) RequestAsync ¶
func (*FakeClient) RequestOneway ¶
func (m *FakeClient) RequestOneway(addr string, cmd *Command) error
func (*FakeClient) RequestSync ¶
func (*FakeClient) Shutdown ¶
func (m *FakeClient) Shutdown()
func (*FakeClient) Start ¶
func (m *FakeClient) Start() error
type Handler ¶
type Handler interface { OnActive(ctx *ChannelContext) OnDeactive(ctx *ChannelContext) OnClose(ctx *ChannelContext) OnError(ctx *ChannelContext, err error) OnMessage(ctx *ChannelContext, cmd *Command) }
Handler event handler
type HeaderOfMapper ¶
HeaderOfMapper converts header to map
type LanguageCode ¶
type LanguageCode int8
LanguageCode the language of client
func (LanguageCode) String ¶
func (lc LanguageCode) String() string
func (*LanguageCode) UnmarshalJSON ¶
func (lc *LanguageCode) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshal language code
type PacketReader ¶
PacketReader reads the packet