rpc

package
v0.0.0-...-48eaceb Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Defaults used by HandleHTTP
	DefaultRPCPath   = "/_goRPC_"
	DefaultDebugPath = "/debug/rpc"
)

Variables

View Source
var DefaultServer = NewServer()
View Source
var (
	ErrShutdown = errors.New("connection is shut down")
)

Functions

func Accept

func Accept(lis net.Listener)

func HandleHTTP

func HandleHTTP()

func NewDebugHTTP

func NewDebugHTTP(server *Server) http.Handler

func Register

func Register(rcvr any) error

Register publishes the receiver's methods in the DefaultServer.

func RegisterName

func RegisterName(name string, rcvr any) error

RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.

func ServeConn

func ServeConn(conn io.ReadWriteCloser)

func ServeRequest

func ServeRequest(codec ServerCodec) error

Types

type ARequest

type ARequest struct {
	ServiceMethod string `json:"method"`
	Seq           uint64 `json:"seq"`
}

func (*ARequest) Method

func (r *ARequest) Method() string

func (*ARequest) SeqId

func (r *ARequest) SeqId() uint64

type AResponse

type AResponse struct {
	ServiceMethod string `json:"method"`
	Seq           uint64 `json:"seq"`
	Error         string `json:"error"`
}

func (*AResponse) ErrorString

func (r *AResponse) ErrorString() string

func (*AResponse) Method

func (r *AResponse) Method() string

func (*AResponse) SeqId

func (r *AResponse) SeqId() uint64

type Call

type Call struct {
	ServiceMethod string
	Args          any
	Reply         any
	Error         error
	Done          chan *Call
}

func (*Call) String

func (call *Call) String() string

type Client

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

func Dial

func Dial(network, address string) (*Client, error)

func DialHTTP

func DialHTTP(network, address string) (*Client, error)

func DialHTTPPath

func DialHTTPPath(network, address, path string) (*Client, error)

DialHTTPPath connects to an HTTP RPC server at the specified network address and path.

func NewClient

func NewClient(codec ClientCodec) *Client

func (*Client) Call

func (client *Client) Call(serviceMethod string, args any, reply any) error

func (*Client) Close

func (client *Client) Close() error

func (*Client) Go

func (client *Client) Go(serviceMethod string, args any, reply any, done chan *Call) *Call

type ClientCodec

type ClientCodec interface {
	WriteRequest(req Request, payload any) error
	ReadResponse() (Response, error)
	ReadPayload(res Response, payload any) error

	Close() error
}

func NewGobClientCodec

func NewGobClientCodec(conn io.ReadWriteCloser) ClientCodec

func NewJSONClientCodec

func NewJSONClientCodec(conn io.ReadWriteCloser) ClientCodec

type Request

type Request interface {
	Method() string
	SeqId() uint64
}

type Response

type Response interface {
	Method() string
	SeqId() uint64
	ErrorString() string
}

type Server

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

func NewServer

func NewServer() *Server

func (*Server) Accept

func (server *Server) Accept(lis net.Listener)

func (*Server) HandleHTTP

func (server *Server) HandleHTTP(rpcPath, debugPath string)

func (*Server) Register

func (server *Server) Register(rcvr any) error

func (*Server) RegisterName

func (server *Server) RegisterName(name string, rcvr any) error

func (*Server) ServeConn

func (server *Server) ServeConn(codec ServerCodec)

func (*Server) ServeHTTP

func (server *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements an http.Handler that answers RPC requests.

func (*Server) ServeRequest

func (server *Server) ServeRequest(codec ServerCodec) error

ServeRequest is like ServeCodec but synchronously serves a single request. It does not close the codec upon completion.

type ServerCodec

type ServerCodec interface {
	ReadRequest() (Request, error)
	ReadPayload(req Request, payload any) error
	WriteResponse(res Response, payload any) error

	Close() error
}

func NewGobServerCodec

func NewGobServerCodec(conn io.ReadWriteCloser) ServerCodec

func NewJSONServerCodec

func NewJSONServerCodec(conn io.ReadWriteCloser) ServerCodec

type ServerError

type ServerError string

func (ServerError) Error

func (e ServerError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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