rpc

package
v0.0.0-...-83adff0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: GPL-3.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrShutdown shutdown error.
	ErrShutdown = errors.New("connection is shut down")
	// ErrNoClient current no rpc client.
	ErrNoClient = errors.New("no rpc client")
)
View Source
var DefaultServer = newServer()

DefaultServer is the default instance of *Server.

Functions

func Accept

func Accept(lis net.Listener)

Accept accepts connections on the listener and serves requests to DefaultServer for each incoming connection. Accept blocks; the caller typically invokes it in a go statement.

func Register

func Register(rcvr interface{}) error

Register publishes the receiver's methods in the DefaultServer.

func RegisterName

func RegisterName(name string, rcvr interface{}) 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 net.Conn)

ServeConn runs the DefaultServer on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement. ServeConn uses the gob wire format (see package gob) on the connection. To use an alternate codec, use ServeCodec.

Types

type Auth

type Auth struct {
	User string
}

Auth handshake struct.

type Call

type Call struct {
	ServiceMethod string      // The name of the service and method to call.
	Args          interface{} // The argument to the function (*struct).
	Reply         interface{} // The reply from the function (*struct).
	Trace         trace.Trace
	Color         string
	RemoteIP      string
	Timeout       time.Duration
	Error         error      // After completion, the error status.
	Done          chan *Call // Strobes when call is complete.
}

Call represents an active RPC.

func (*Call) Finish

func (call *Call) Finish()

Finish must called after Go.

type Client

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

Client wrapper is a client holder with implements pinger.

func Dial

func Dial(addr string, timeout xtime.Duration, bkc *breaker.Config) *Client

Dial connects to an RPC server at the specified network address.

func (*Client) Call

func (c *Client) Call(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) (err error)

Call invokes the named function, waits for it to complete, and returns its error status.

func (*Client) Close

func (c *Client) Close()

Close close client connection.

type Client2

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

Client2 support for load balancing and service discovery.

func NewDiscoveryCli

func NewDiscoveryCli(appID string, cf *ClientConfig) (c *Client2)

NewDiscoveryCli new discovery client.

func (*Client2) Boardcast

func (c *Client2) Boardcast(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) (err error)

Boardcast boardcast all rpc client.

func (*Client2) Call

func (c *Client2) Call(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) (err error)

Call invokes the named function, waits for it to complete, and returns its error status. this include rpc.Client.Call method, and takes a timeout.

type ClientConfig

type ClientConfig struct {
	Policy  string
	Zone    string
	Cluster string
	Color   string
	Timeout xtime.Duration
	Breaker *breaker.Config
}

ClientConfig rpc client config.

type Interceptor

type Interceptor interface {
	Rate(context.Context) error
	Stat(context.Context, interface{}, error)
	Auth(context.Context, net.Addr, string) error // ip, token
}

Interceptor interface.

type Request

type Request struct {
	Color         string        // color
	RemoteIP      string        // remoteIP
	Timeout       time.Duration // timeout
	ServiceMethod string        // format: "Service.Method"
	Seq           uint64        // sequence number chosen by client
	Trace         TraceInfo     // trace info
	// contains filtered or unexported fields
}

Request is a header written before every RPC call. It is used internally but documented here as an aid to debugging, such as when analyzing network traffic.

type Response

type Response struct {
	ServiceMethod string // echoes that of the Request
	Seq           uint64 // echoes that of the request
	Error         string // error, if any.
}

Response is a header written before every RPC return. It is used internally but documented here as an aid to debugging, such as when analyzing network traffic.

type Server

type Server struct {
	Interceptor Interceptor //拦截器
	// contains filtered or unexported fields
}

Server represents an RPC Server.

func NewServer

func NewServer(c *ServerConfig) *Server

NewServer new a rpc server.

func (*Server) Accept

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

Accept accepts connections on the listener and serves requests for each incoming connection. Accept blocks until the listener returns a non-nil error. The caller typically invokes Accept in a go statement.

func (*Server) Close

func (server *Server) Close() error

Close stop the rpc server.

func (*Server) Register

func (server *Server) Register(rcvr interface{}) (err error)

Register publishes in the server the set of methods of the receiver value that satisfy the following conditions:

  • exported method of exported type
  • two arguments, both of exported type
  • the second argument is a pointer
  • one return value, of type error

It returns an error if the receiver is not an exported type or has no suitable methods. It also logs the error using package log. The client accesses each method using a string of the form "Type.Method", where Type is the receiver's concrete type.

func (*Server) RegisterName

func (server *Server) RegisterName(name string, rcvr interface{}) (err error)

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

func (*Server) ServeConn

func (server *Server) ServeConn(conn net.Conn)

ServeConn runs the server on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement. ServeConn uses the gob wire format (see package gob) on the connection. To use an alternate codec, use ServeCodec.

type ServerConfig

type ServerConfig struct {
	Proto string `dsn:"network"`
	Addr  string `dsn:"address"`
}

ServerConfig rpc server settings.

type ServerError

type ServerError string

ServerError represents an error that has been returned from the remote side of the RPC connection.

func (ServerError) Error

func (e ServerError) Error() string

type TraceInfo

type TraceInfo struct {
	ID       uint64
	SpanID   uint64
	ParentID uint64
	Level    int32
	Sampled  bool
	Caller   string
	Title    string
	Time     int64
}

TraceInfo propagate trace propagate gorpc call

func (*TraceInfo) Get

func (i *TraceInfo) Get(key string) string

Get implement trace.Carrier

func (*TraceInfo) Set

func (i *TraceInfo) Set(key string, val string)

Set implement trace.Carrier

Directories

Path Synopsis
test
Package liverpc .
Package liverpc .
benchmark/bench/proto
Package grpc is a generated protocol buffer package.
Package grpc is a generated protocol buffer package.
proto/testproto
Package testproto is a generated protocol buffer package.
Package testproto is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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