grpc

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrServiceNotAvailable 服务不可用,通常是因为没有查询到中心节点(coordinate)
	ErrServiceNotAvailable = errors.New("caller service not available")

	// ErrConfigConvert 配置转换失败
	ErrConfigConvert = errors.New("convert linker config")

	// ErrCantFindNode 在注册中心找不到对应的服务节点
	ErrCantFindNode = errors.New("can't find service node in center")
)
View Source
var (
	DefaultClientParm = ClientParm{
		PoolInitNum:        8,
		PoolCapacity:       64,
		MaxConcurrentCalls: 1024,
		CallTimeout:        time.Second * 10,
		PoolIdle:           time.Second * 100,
	}
)
View Source
var (
	// ErrServiceUnavailiable 没有可用的服务
	ErrServiceUnavailiable = errors.New("service not registered")
)

Functions

This section is empty.

Types

type Client

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

Client 调用器

func BuildClientWithOption

func BuildClientWithOption(opts ...ClientOption) *Client

func (*Client) Call

func (c *Client) Call(ctx context.Context, addr, method string, args interface{}, reply interface{}, opts ...interface{}) error

func (*Client) CallWait

func (c *Client) CallWait(ctx context.Context, addr, methon string, args, reply interface{}, opts ...interface{}) error

func (*Client) Init

func (c *Client) Init() error

type ClientOption

type ClientOption func(*ClientParm)

Option config wraps

func ClientAppendStreamInterceptors

func ClientAppendStreamInterceptors(interceptor grpc.StreamClientInterceptor) ClientOption

func ClientAppendUnaryInterceptors

func ClientAppendUnaryInterceptors(interceptor grpc.UnaryClientInterceptor) ClientOption

func WithCallTimeout

func WithCallTimeout(callTimeout time.Duration) ClientOption

func WithClientConns

func WithClientConns(lst []string) ClientOption

WithClientConns 目标服务器列表地址(静态绑定

func WithClientPoolCapacity

func WithClientPoolCapacity(num int) ClientOption

WithPoolCapacity 连接池的容量大小

func WithClientPoolIdle

func WithClientPoolIdle(second int) ClientOption

WithPoolIdle 连接池的最大闲置时间

func WithClientPoolInitNum

func WithClientPoolInitNum(num int) ClientOption

WithPoolInitNum 连接池初始化数量

func WithDialOptions

func WithDialOptions(opts ...grpc.DialOption) ClientOption

func WithMaxConcurrentCalls

func WithMaxConcurrentCalls(maxCalls int) ClientOption

type ClientParm

type ClientParm struct {
	PoolInitNum  int
	PoolCapacity int
	PoolIdle     time.Duration

	MaxConcurrentCalls int
	CallTimeout        time.Duration

	AddressLst []string

	UnaryInterceptors  []grpc.UnaryClientInterceptor
	StreamInterceptors []grpc.StreamClientInterceptor
	// contains filtered or unexported fields
}

Parm 调用器配置项

type RegistHandler

type RegistHandler func(*grpc.Server)

type Server

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

Server RPC 服务端

func BuildServerWithOption

func BuildServerWithOption(opts ...ServerOption) *Server

func (*Server) Close

func (s *Server) Close()

Close 退出处理

func (*Server) Init

func (s *Server) Init() error

func (*Server) Run

func (s *Server) Run()

Run 运行

func (*Server) Server

func (s *Server) Server() interface{}

Get 获取rpc 服务器

type ServerOption

type ServerOption func(*ServerParm)

Option config wraps

func ServerAppendStreamInterceptors

func ServerAppendStreamInterceptors(interceptor grpc.StreamServerInterceptor) ServerOption

func ServerAppendUnaryInterceptors

func ServerAppendUnaryInterceptors(interceptor grpc.UnaryServerInterceptor) ServerOption

func ServerRegisterHandler

func ServerRegisterHandler(handler RegistHandler) ServerOption

func WithServerGracefulStop

func WithServerGracefulStop() ServerOption

func WithServerListen

func WithServerListen(address string) ServerOption

WithListen 服务器侦听地址配置

type ServerParm

type ServerParm struct {
	ListenAddr string

	UnaryInterceptors  []grpc.UnaryServerInterceptor
	StreamInterceptors []grpc.StreamServerInterceptor

	Handler RegistHandler

	GracefulStop bool
}

Parm Service 配置

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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