rpc

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConn

func NewConn(target string, opt ...grpc.DialOption) (*grpc.ClientConn, error)

Types

type ClientConfig

type ClientConfig struct {
	Dial    ztime.Duration
	Timeout ztime.Duration
	// Breaker                *breaker.Config
	Method                 map[string]*ClientConfig
	Clusters               []string
	Zone                   string
	Subset                 int
	NonBlock               bool
	KeepAliveInterval      ztime.Duration
	KeepAliveTimeout       ztime.Duration
	KeepAliveWithoutStream bool
}

type RpcClient

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

func DefaultClient

func DefaultClient() *RpcClient

func NewClient

func NewClient(conf *ClientConfig, opt ...grpc.DialOption) *RpcClient

func (*RpcClient) Dial

func (c *RpcClient) Dial(ctx context.Context, target string, opts ...grpc.DialOption) (conn *grpc.ClientConn, err error)

func (*RpcClient) DialTLS

func (c *RpcClient) DialTLS(ctx context.Context, target string, file string, name string, opts ...grpc.DialOption) (conn *grpc.ClientConn, err error)

func (*RpcClient) SetConfig

func (c *RpcClient) SetConfig(conf *ClientConfig) (err error)

SetConfig hot reloads client config

func (*RpcClient) Use

func (c *RpcClient) Use(handlers ...grpc.UnaryClientInterceptor) *RpcClient

func (*RpcClient) UseOpt

func (c *RpcClient) UseOpt(opts ...grpc.DialOption) *RpcClient

type RpcServer

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

func NewServer

func NewServer(config *RpcServerConfig, opt ...grpc.ServerOption) (s *RpcServer)

NewServer returns a new blank Server instance with a default server interceptor.

func (*RpcServer) Run

func (s *RpcServer) Run(addr string) error

Run create a tcp listener and start goroutine for serving each incoming request. Run will return a non-nil error unless Stop or GracefulStop is called.

func (*RpcServer) Serve

func (s *RpcServer) Serve(lis net.Listener) error

Serve accepts incoming connections on the listener lis, creating a new ServerTransport and service goroutine for each. Serve will return a non-nil error unless Stop or GracefulStop is called.

func (*RpcServer) Server

func (s *RpcServer) Server() *grpc.Server

Server return the grpc server for registering service.

func (*RpcServer) SetConfig

func (s *RpcServer) SetConfig(config *RpcServerConfig) (err error)

SetConfig hot reloads server config

func (*RpcServer) Shutdown

func (s *RpcServer) Shutdown(ctx context.Context) (err error)

func (*RpcServer) Start

func (s *RpcServer) Start() (*RpcServer, error)

Start create a new goroutine run server with configured listen addr will panic if any error happend return server itself

func (*RpcServer) Use

func (s *RpcServer) Use(handlers ...grpc.UnaryServerInterceptor) *RpcServer

Use attachs a global inteceptor to the server. For example, this is the right place for a rate limiter or error management inteceptor.

type RpcServerConfig

type RpcServerConfig struct {
	Addr              string
	Timeout           ztime.Duration
	IdleTimeout       ztime.Duration
	MaxLifeTime       ztime.Duration
	ForceCloseWait    ztime.Duration
	KeepAliveInterval ztime.Duration
	KeepAliveTimeout  ztime.Duration
}

func DefaultRpcServerConfig

func DefaultRpcServerConfig() *RpcServerConfig

type TimeoutCallOption

type TimeoutCallOption struct {
	*grpc.EmptyCallOption
	Timeout ztime.Duration
}

func WithTimeoutCallOption

func WithTimeoutCallOption(timeout ztime.Duration) *TimeoutCallOption

Jump to

Keyboard shortcuts

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