grpc

package
v0.0.0-...-457ba4f Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

* User: cr-mao Date: 2023/8/17 14:27 Email: crmao@qq.com Desc: server.go

Index

Constants

This section is empty.

Variables

View Source
var ErrConnShutdown = errors.New("grpc conn shutdown")

Functions

func UnaryCrashInterceptor

func UnaryCrashInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler) (resp interface{}, err error)

防止panic crash 中间件

Types

type ClientBuilder

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

func NewClientBuilder

func NewClientBuilder(opts *ClientOptions) *ClientBuilder

func (*ClientBuilder) GetConn

func (b *ClientBuilder) GetConn(target string) (*grpc.ClientConn, error)

Build 构建连接

type ClientOptions

type ClientOptions struct {
	PoolSize int
	DialOpts []grpc.DialOption
}

type Pool

type Pool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Pool) Get

func (p *Pool) Get() (*grpc.ClientConn, error)

type Server

type Server struct {
	*grpc.Server
	// contains filtered or unexported fields
}

Server is a gRPC server wrapper.

func NewServer

func NewServer(addr string, opts ...ServerOption) (*Server, error)

NewServer creates a gRPC server by options.

func (*Server) Addr

func (s *Server) Addr() string

Addr 监听地址

func (*Server) Endpoint

func (s *Server) Endpoint() *endpoint.Endpoint

Endpoint return a real address to registry endpoint. examples:

grpc://127.0.0.1:9000?is_secure=false,

func (*Server) Scheme

func (s *Server) Scheme() string

Scheme 协议

func (*Server) Start

func (s *Server) Start() error

Start start the gRPC server.

func (*Server) Stop

func (s *Server) Stop() error

Stop stop the gRPC server.

type ServerOption

type ServerOption func(o *Server)

ServerOption is gRPC server option.

func WithGrpcOpts

func WithGrpcOpts(opts ...grpc.ServerOption) ServerOption

WithGrpcOpts with grpc options.

func WithUnaryInterceptor

func WithUnaryInterceptor(in ...grpc.UnaryServerInterceptor) ServerOption

WithUnaryInterceptor returns a ServerOption that sets the UnaryServerInterceptor for the server.

Directories

Path Synopsis
resolver

Jump to

Keyboard shortcuts

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