gosr

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2020 License: MIT Imports: 12 Imported by: 0

README

gosr

a simple frame of send and receive on conn for golang

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTimeout ...
	ErrTimeout = errors.New("timeout")
)

Functions

func NewBlockReadWriteCloser added in v0.0.6

func NewBlockReadWriteCloser() io.ReadWriteCloser

NewBlockReadWriteCloser ...

func NewTestConn added in v0.0.6

func NewTestConn() (local, remote net.Conn)

NewTestConn ...

Types

type Call added in v0.0.2

type Call struct {
	ServiceMethod interface{}
	Args          interface{} // The argument to the function (*struct).
	Reply         interface{} // The reply from the function (*struct).
	Error         error       // After completion, the error status.
	Done          chan *Call  // Strobes when call is complete.
	// contains filtered or unexported fields
}

Call represents an active RPC.

type Client

type Client interface {
	Close() error
	Go(serviceMethod, args interface{}, reply interface{}, done chan *Call) *Call
	Call(serviceMethod, args interface{}, reply interface{}) error
	CallAsync(serviceMethod, args, reply interface{}, cb func(*Call))
	CallWithoutReply(serviceMethod, args interface{}) error
	Wait()
}

Client ...

func NewClientWithCodec added in v0.0.2

func NewClientWithCodec(codec ClientCodec) Client

NewClientWithCodec is like NewClient but uses the specified codec to encode requests and decode responses.

type ClientCodec added in v0.0.2

type ClientCodec interface {
	GetSeq(req *Request) (seq interface{})
	WriteRequest(req *Request, args interface{}) error
	ReadResponseHeader(*Response) error
	ReadResponseBody(resp *Response, reply interface{}) error
	Close() error
}

A ClientCodec implements writing of RPC requests and reading of RPC responses for the p side of an RPC session. The p calls WriteRequest to write a request to the connection and calls ReadResponseHeader and ReadResponseBody in pairs to read responses. The p calls Close when finished with the connection. ReadResponseBody may be called with a nil argument to force the body of the response to be read and then discarded. See NewClient's comment for information about concurrent access.

type CodecAdapter added in v0.0.7

type CodecAdapter struct {
	DualCodec
}

CodecAdapter ...

func (CodecAdapter) ReadRequestHeader added in v0.0.7

func (p CodecAdapter) ReadRequestHeader(req *Request) error

ReadRequestHeader ...

func (CodecAdapter) ReadResponseHeader added in v0.0.7

func (p CodecAdapter) ReadResponseHeader(rsp *Response) error

ReadResponseHeader ...

type Dual added in v0.0.6

type Dual interface {
	Server
	Client() Client
}

Dual ...

func NewDualWithCodec added in v0.0.6

func NewDualWithCodec(codec DualCodec, handlers *HandlerManager, ctx interface{}) Dual

NewDualWithCodec ...

type DualCodec added in v0.0.6

type DualCodec interface {
	GetSeq(*Request) (seq interface{})
	WriteRequest(*Request, interface{}) error
	WriteResponse(*Response, interface{}) error
	ReadHeader(*DualHeader) error
	ReadRequestBody(req *Request, args interface{}) error
	ReadResponseBody(resp *Response, reply interface{}) error
	Close() error
}

DualCodec ...

type DualHeader added in v0.0.6

type DualHeader struct {
	Seq           interface{}
	ServiceMethod interface{}
	Error         error
	Context       interface{}
	IsRequest     bool
}

DualHeader ...

func (*DualHeader) ToRequest added in v0.0.6

func (p *DualHeader) ToRequest(request *Request)

ToRequest ...

func (*DualHeader) ToResponse added in v0.0.6

func (p *DualHeader) ToResponse(response *Response)

ToResponse ...

type Error

type Error error

Error ...

var (
	// ErrClosed ...
	ErrClosed Error = fmt.Errorf("[gosr] closed")
)

func Errof

func Errof(format string, args ...interface{}) Error

Errof ...

type HandlerManager added in v0.0.6

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

HandlerManager ...

func NewHandlerManager added in v0.0.6

func NewHandlerManager() *HandlerManager

NewHandlerManager ...

func (*HandlerManager) Register added in v0.0.6

func (p *HandlerManager) Register(serviceMethod interface{}, rcvr interface{}) error

Register ...

type Request added in v0.0.2

type Request struct {
	Seq           interface{}
	ServiceMethod interface{}
	Context       interface{}
}

Request ...

type Response added in v0.0.2

type Response struct {
	Seq           interface{}
	ServiceMethod interface{}
	Error         error
	Context       interface{}
}

Response ...

type ResponseWriter added in v0.0.6

type ResponseWriter struct {
	*Response
	// contains filtered or unexported fields
}

ResponseWriter ...

func (*ResponseWriter) Free added in v0.0.7

func (p *ResponseWriter) Free()

Free ...

func (*ResponseWriter) Reply added in v0.0.6

func (p *ResponseWriter) Reply(reply interface{}) error

Reply ...

type Server added in v0.0.6

type Server interface {
	Serve()
	ServeRequest() error
	ReadFunction(*ServerFunction) error
	SetContext(interface{})
}

Server ...

func NewServerWithCodec added in v0.0.6

func NewServerWithCodec(handlerManager *HandlerManager, codec ServerCodec, ctx interface{}) Server

NewServerWithCodec ...

type ServerCodec added in v0.0.6

type ServerCodec interface {
	ReadRequestHeader(req *Request) error
	ReadRequestBody(req *Request, args interface{}) error
	WriteResponse(resp *Response, reply interface{}) error
}

ServerCodec ...

type ServerFunction added in v0.0.6

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

ServerFunction ...

func (*ServerFunction) Call added in v0.0.6

func (p *ServerFunction) Call()

Call ...

Jump to

Keyboard shortcuts

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