rpc2

package
v0.0.0-...-5bc8b1e Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2015 License: MIT Imports: 12 Imported by: 18

Documentation

Index

Constants

View Source
const (
	TYPE_CALL     = 0
	TYPE_RESPONSE = 1
	TYPE_NOTIFY   = 2
)

Variables

This section is empty.

Functions

func AddrToString

func AddrToString(addr net.Addr) string

func MakeMethodName

func MakeMethodName(prot string, method string) string

func SplitMethodName

func SplitMethodName(n string) (p string, m string)

Types

type AlreadyRegisteredError

type AlreadyRegisteredError struct {
	// contains filtered or unexported fields
}

func (AlreadyRegisteredError) Error

func (a AlreadyRegisteredError) Error() string

type Call

type Call struct {
	// contains filtered or unexported fields
}

func (*Call) Init

func (c *Call) Init()

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(xp Transporter, f UnwrapErrorFunc) *Client

func (*Client) Call

func (c *Client) Call(method string, arg interface{}, res interface{}) (err error)

type ConPackage

type ConPackage struct {
	Decoder
	// contains filtered or unexported fields
}

func NewConPackage

func NewConPackage(c net.Conn, mh *codec.MsgpackHandle) *ConPackage

func (*ConPackage) Close

func (c *ConPackage) Close() error

func (*ConPackage) GetRemoteAddr

func (c *ConPackage) GetRemoteAddr() net.Addr

func (*ConPackage) ReadByte

func (c *ConPackage) ReadByte() (b byte, e error)

func (*ConPackage) Write

func (c *ConPackage) Write(b []byte) (err error)

type DecodeNext

type DecodeNext func(interface{}) error

type Decoder

type Decoder interface {
	Decode(interface{}) error
}

type DisconnectedError

type DisconnectedError struct{}

func (DisconnectedError) Error

func (e DisconnectedError) Error() string

type Dispatch

type Dispatch struct {
	// contains filtered or unexported fields
}

func NewDispatch

func NewDispatch(xp Transporter, l LogInterface, wef WrapErrorFunc) *Dispatch

func (*Dispatch) Call

func (d *Dispatch) Call(name string, arg interface{}, res interface{}, f UnwrapErrorFunc) (err error)

func (*Dispatch) Dispatch

func (d *Dispatch) Dispatch(m *Message) (err error)

func (*Dispatch) RegisterEOFHook

func (d *Dispatch) RegisterEOFHook(h EOFHook) error

RegisterEOFHook registers a function to call when the dispatcher hits EOF. The hook will be called with whatever error caused the channel to close. Usually this should be io.EOF, but it can of course be otherwise.

func (*Dispatch) RegisterProtocol

func (d *Dispatch) RegisterProtocol(p Protocol) (err error)

func (*Dispatch) Reset

func (d *Dispatch) Reset(eofError error) error

type Dispatcher

type Dispatcher interface {
	Dispatch(m *Message) error
	Call(name string, arg interface{}, res interface{}, f UnwrapErrorFunc) error
	RegisterProtocol(Protocol) error
	RegisterEOFHook(EOFHook) error
	Reset(error) error
}

type DispatcherError

type DispatcherError struct {
	// contains filtered or unexported fields
}

func NewDispatcherError

func NewDispatcherError(d string, a ...interface{}) DispatcherError

func (DispatcherError) Error

func (p DispatcherError) Error() string

type EOFHook

type EOFHook func(error)

EOFHook is typically called when a transport has to shut down. We supply it with the exact error that caused the shutdown, which should be io.EOF under normal circumstances.

type EofError

type EofError struct{}

func (EofError) Error

func (e EofError) Error() string

type Errors

type Errors struct {
	// contains filtered or unexported fields
}

func (*Errors) Error

func (e *Errors) Error() error

func (*Errors) Push

func (es *Errors) Push(e error) bool

type LogFactory

type LogFactory interface {
	NewLog(net.Addr) LogInterface
}

type LogInterface

type LogInterface interface {
	TransportStart()
	TransportError(error)
	ServerCall(int, string, error, interface{})
	ServerReply(int, string, error, interface{})
	ClientCall(int, string, interface{})
	ClientReply(int, string, error, interface{})
	StartProfiler(format string, args ...interface{}) Profiler
	UnexpectedReply(int)
	Warning(format string, args ...interface{})
}

type LogOptions

type LogOptions interface {
	ShowAddress() bool
	ShowArg() bool
	ShowResult() bool
	Profile() bool
	ClientTrace() bool
	ServerTrace() bool
	TransportStart() bool
}

type LogOutput

type LogOutput interface {
	Error(s string, args ...interface{})
	Warning(s string, args ...interface{})
	Info(s string, args ...interface{})
	Debug(s string, args ...interface{})
	Profile(s string, args ...interface{})
}

type Message

type Message struct {
	// contains filtered or unexported fields
}

func NewMessage

func NewMessage(t Transporter, nFields int) Message

func (*Message) Decode

func (m *Message) Decode(i interface{}) (err error)

func (*Message) DecodeError

func (m *Message) DecodeError(f UnwrapErrorFunc) (app error, dispatch error)

func (*Message) Encode

func (m *Message) Encode(i interface{}) error

func (*Message) WrapError

func (m *Message) WrapError(f WrapErrorFunc, e error) interface{}

type MethodNotFoundError

type MethodNotFoundError struct {
	// contains filtered or unexported fields
}

func (MethodNotFoundError) Error

func (m MethodNotFoundError) Error() string

type Packetizer

type Packetizer struct {
	// contains filtered or unexported fields
}

func NewPacketizer

func NewPacketizer(d Dispatcher, t Transporter) *Packetizer

func (*Packetizer) Clear

func (p *Packetizer) Clear()

func (*Packetizer) Packetize

func (p *Packetizer) Packetize() (err error)

type PacketizerError

type PacketizerError struct {
	// contains filtered or unexported fields
}

func NewPacketizerError

func NewPacketizerError(d string, a ...interface{}) PacketizerError

func (PacketizerError) Error

func (p PacketizerError) Error() string

type Profiler

type Profiler interface {
	Stop()
}

type Protocol

type Protocol struct {
	Name      string
	Methods   map[string]ServeHook
	WrapError WrapErrorFunc
}

type ProtocolNotFoundError

type ProtocolNotFoundError struct {
	// contains filtered or unexported fields
}

func (ProtocolNotFoundError) Error

func (p ProtocolNotFoundError) Error() string

type Request

type Request struct {
	// contains filtered or unexported fields
}

type ServeHook

type ServeHook func(DecodeNext) (interface{}, error)

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(xp *Transport, f WrapErrorFunc) *Server

func (*Server) Register

func (s *Server) Register(p Protocol) (err error)

func (*Server) RegisterEOFHook

func (s *Server) RegisterEOFHook(h EOFHook) error

RegisterEOFHook registers a callback that's called when there's and EOF condition on the underlying channel.

func (*Server) Run

func (s *Server) Run(bg bool) error

type SimpleLog

type SimpleLog struct {
	Addr net.Addr
	Out  LogOutput
	Opts LogOptions
}

func (SimpleLog) ClientCall

func (s SimpleLog) ClientCall(q int, meth string, arg interface{})

func (SimpleLog) ClientReply

func (s SimpleLog) ClientReply(q int, meth string, err error, res interface{})

func (SimpleLog) ServerCall

func (s SimpleLog) ServerCall(q int, meth string, err error, arg interface{})

func (SimpleLog) ServerReply

func (s SimpleLog) ServerReply(q int, meth string, err error, res interface{})

func (SimpleLog) StartProfiler

func (s SimpleLog) StartProfiler(format string, args ...interface{}) Profiler

func (SimpleLog) TransportError

func (l SimpleLog) TransportError(e error)

func (SimpleLog) TransportStart

func (l SimpleLog) TransportStart()

func (SimpleLog) UnexpectedReply

func (s SimpleLog) UnexpectedReply(seqno int)

func (SimpleLog) Warning

func (s SimpleLog) Warning(format string, args ...interface{})

type SimpleLogFactory

type SimpleLogFactory struct {
	// contains filtered or unexported fields
}

func NewSimpleLogFactory

func NewSimpleLogFactory(out LogOutput, opts LogOptions) SimpleLogFactory

func (SimpleLogFactory) NewLog

func (s SimpleLogFactory) NewLog(a net.Addr) LogInterface

type SimpleLogOptions

type SimpleLogOptions struct{}

func (SimpleLogOptions) ClientTrace

func (so SimpleLogOptions) ClientTrace() bool

func (SimpleLogOptions) Profile

func (so SimpleLogOptions) Profile() bool

func (SimpleLogOptions) ServerTrace

func (so SimpleLogOptions) ServerTrace() bool

func (SimpleLogOptions) ShowAddress

func (so SimpleLogOptions) ShowAddress() bool

func (SimpleLogOptions) ShowArg

func (so SimpleLogOptions) ShowArg() bool

func (SimpleLogOptions) ShowResult

func (so SimpleLogOptions) ShowResult() bool

func (SimpleLogOptions) TransportStart

func (so SimpleLogOptions) TransportStart() bool

type SimpleLogOutput

type SimpleLogOutput struct{}

func (SimpleLogOutput) Debug

func (s SimpleLogOutput) Debug(fmt string, args ...interface{})

func (SimpleLogOutput) Error

func (s SimpleLogOutput) Error(fmt string, args ...interface{})

func (SimpleLogOutput) Info

func (s SimpleLogOutput) Info(fmt string, args ...interface{})

func (SimpleLogOutput) Profile

func (s SimpleLogOutput) Profile(fmt string, args ...interface{})

func (SimpleLogOutput) Warning

func (s SimpleLogOutput) Warning(fmt string, args ...interface{})

type SimpleProfiler

type SimpleProfiler struct {
	// contains filtered or unexported fields
}

func (SimpleProfiler) Stop

func (s SimpleProfiler) Stop()

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

func NewTransport

func NewTransport(c net.Conn, l LogFactory, wef WrapErrorFunc) *Transport

func (*Transport) Decode

func (t *Transport) Decode(i interface{}) (err error)

func (*Transport) Encode

func (t *Transport) Encode(i interface{}) (err error)

func (*Transport) GetDispatcher

func (t *Transport) GetDispatcher() (d Dispatcher, err error)

func (*Transport) GetRemoteAddr

func (t *Transport) GetRemoteAddr() (ret net.Addr)

func (*Transport) IsConnected

func (t *Transport) IsConnected() bool

func (*Transport) RawWrite

func (t *Transport) RawWrite(b []byte) (err error)

func (*Transport) ReadByte

func (t *Transport) ReadByte() (b byte, err error)

func (*Transport) ReadLock

func (t *Transport) ReadLock()

func (*Transport) ReadUnlock

func (t *Transport) ReadUnlock()

type Transporter

type Transporter interface {
	RawWrite([]byte) error
	ReadByte() (byte, error)
	Decode(interface{}) error
	Encode(interface{}) error
	GetDispatcher() (Dispatcher, error)
	ReadLock()
	ReadUnlock()
}

type UnwrapErrorFunc

type UnwrapErrorFunc func(nxt DecodeNext) (error, error)

type WrapErrorFunc

type WrapErrorFunc func(error) interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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