remote

package
v2.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StateDisconnected disconnected status
	StateDisconnected int32 = iota
	// StateConnected connected status
	StateConnected
	// StateClosing closing status
	StateClosing
)
View Source
const (
	// ProtoJSON json codec
	ProtoJSON = iota
	// ProtoRocketMQ rocket mq codec
	ProtoRocketMQ
)

Variables

View Source
var ErrBadContent = errors.New("bad content")

ErrBadContent indicate the data is not recognized

View Source
var ErrDisconnected = errors.New("disconnected")

ErrDisconnected disconnected error

View Source
var ErrNeedContent = errors.New("need content")

ErrNeedContent indicate need to read data

Functions

func ReadPacket

func ReadPacket(r io.Reader) ([]byte, error)

ReadPacket read one packet

Types

type ChannelConfig

type ChannelConfig struct {
	ClientConfig

	Encoder
	PacketReader
	Decoder
	Handler
	// contains filtered or unexported fields
}

ChannelConfig contains channel's configuration

type ChannelContext

type ChannelContext struct {
	Address string
	Conn    net.Conn
}

ChannelContext channel's context

func (*ChannelContext) String

func (ctx *ChannelContext) String() string

type ChannelState

type ChannelState int

ChannelState channel state type

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 Int16ToCode

func Int16ToCode(code int16) Code

Int16ToCode from int16 to Code

func (Code) ToInt16

func (c Code) ToInt16() int16

ToInt16 to int16 value

func (*Code) UnmarshalJSON

func (c *Code) UnmarshalJSON(b []byte) error

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) Decode

func (cmd *Command) Decode(buf []byte) (interface{}, error)

Decode decode the raw command data

func (*Command) Encode

func (cmd *Command) Encode(interface{}) ([]byte, error)

Encode encode the command

func (*Command) ID

func (cmd *Command) ID() int64

ID returns the request ID

func (*Command) IsOneway

func (cmd *Command) IsOneway() bool

IsOneway returns true if the command is oneway, otherwise false

func (*Command) MarkResponse

func (cmd *Command) MarkResponse()

MarkResponse mark the command as response

func (*Command) Read

func (cmd *Command) Read(r io.Reader) ([]byte, error)

Read decode the raw command data

func (*Command) String

func (cmd *Command) String() string

type Decoder

type Decoder interface {
	Decode([]byte) (*Command, error)
}

Decoder decode the bytes to the object

type DecoderFunc

type DecoderFunc func([]byte) (*Command, error)

DecoderFunc decoder function

func (DecoderFunc) Decode

func (f DecoderFunc) Decode(d []byte) (*Command, error)

Decode call decoder function

type Encoder

type Encoder interface {
	Encode(*Command) ([]byte, error)
}

Encoder encode the object to the bytes

type EncoderFunc

type EncoderFunc func(*Command) ([]byte, error)

EncoderFunc encoder function

func (EncoderFunc) Encode

func (f EncoderFunc) Encode(cmd *Command) ([]byte, error)

Encode call encoder function

type FakeClient

type FakeClient struct {
}

func (*FakeClient) RequestAsync

func (m *FakeClient) RequestAsync(addr string, cmd *Command, timeout time.Duration, callback func(*Command, error)) error

func (*FakeClient) RequestOneway

func (m *FakeClient) RequestOneway(addr string, cmd *Command) error

func (*FakeClient) RequestSync

func (m *FakeClient) RequestSync(addr string, cmd *Command, timeout time.Duration) (*Command, error)

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

type HeaderOfMapper interface {
	ToMap() map[string]string
}

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) ToInt8

func (lc LanguageCode) ToInt8() int8

ToInt8 to int16 value

func (*LanguageCode) UnmarshalJSON

func (lc *LanguageCode) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshal language code

type PacketReader

type PacketReader interface {
	Read(io.Reader) ([]byte, error)
}

PacketReader reads the packet

type PacketReaderFunc

type PacketReaderFunc func(io.Reader) ([]byte, error)

PacketReaderFunc packet read function

func (PacketReaderFunc) Read

func (f PacketReaderFunc) Read(r io.Reader) ([]byte, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL