grpc

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial(ctx context.Context, opts ...GRPCClientOption) (*grpc.ClientConn, error)

Dial 创建到gRPC服务器的连接

func StreamServerInterceptor

func StreamServerInterceptor(m ...middleware.Middleware) grpc.StreamServerInterceptor

StreamServerInterceptor 创建一个gRPC流拦截器,使用phantasm中间件

func TranslateError

func TranslateError(err error) error

TranslateError 将phantasm错误转换为gRPC错误

func UnaryServerInterceptor

func UnaryServerInterceptor(m ...middleware.Middleware) grpc.UnaryServerInterceptor

UnaryServerInterceptor 创建一个gRPC一元拦截器,使用phantasm中间件

Types

type GRPCClientOption

type GRPCClientOption func(*GRPCClientOptions)

GRPCClientOption 是gRPC客户端选项

func WithBalancer

func WithBalancer(balancer string) GRPCClientOption

WithBalancer 设置负载均衡器

func WithClientInterceptor

func WithClientInterceptor(interceptors ...grpc.UnaryClientInterceptor) GRPCClientOption

WithClientInterceptor 添加客户端拦截器

func WithClientTLS

func WithClientTLS(cert string) GRPCClientOption

WithClientTLS 设置客户端TLS

func WithClientTimeout

func WithClientTimeout(timeout time.Duration) GRPCClientOption

WithClientTimeout 设置客户端超时

func WithDialOption

func WithDialOption(opts ...grpc.DialOption) GRPCClientOption

WithDialOption 添加拨号选项

func WithEndpoint

func WithEndpoint(endpoint string) GRPCClientOption

WithEndpoint 设置客户端端点

func WithInsecure

func WithInsecure() GRPCClientOption

WithInsecure 设置不安全连接

type GRPCClientOptions

type GRPCClientOptions struct {
	Endpoint     string
	Timeout      time.Duration
	TLSCert      string
	Insecure     bool
	Balancer     string
	DialOptions  []grpc.DialOption
	Interceptors []grpc.UnaryClientInterceptor
}

GRPCClientOptions 是gRPC客户端选项集合

type GRPCServer

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

GRPCServer 是gRPC服务器

func NewGRPCServer

func NewGRPCServer(opts ...GRPCServerOption) (*GRPCServer, error)

NewGRPCServer 创建一个新的gRPC服务器

func (*GRPCServer) Endpoint

func (s *GRPCServer) Endpoint() (*url.URL, error)

Endpoint 返回gRPC服务器的URL端点

func (*GRPCServer) RegisterService

func (s *GRPCServer) RegisterService(desc *grpc.ServiceDesc, impl interface{})

RegisterService 注册gRPC服务

func (*GRPCServer) Server

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

Server 返回底层gRPC服务器

func (*GRPCServer) Start

func (s *GRPCServer) Start(ctx context.Context) error

Start 启动gRPC服务器

func (*GRPCServer) Stop

func (s *GRPCServer) Stop(ctx context.Context) error

Stop 停止gRPC服务器

type GRPCServerOption

type GRPCServerOption func(*GRPCServer)

GRPCServerOption 是gRPC服务器选项

func WithAddress

func WithAddress(addr string) GRPCServerOption

WithAddress 设置服务器地址

func WithGracefulStop

func WithGracefulStop(graceful bool) GRPCServerOption

WithGracefulStop 设置是否优雅停止

func WithGroup

func WithGroup(group string) GRPCServerOption

WithGroup 设置服务分组

func WithMiddleware

func WithMiddleware(m ...middleware.Middleware) GRPCServerOption

WithMiddleware 设置gRPC中间件

func WithName

func WithName(name string) GRPCServerOption

WithName 设置服务名称

func WithTLS

func WithTLS(cert, key string) GRPCServerOption

WithTLS 设置TLS配置

func WithTimeout

func WithTimeout(timeout time.Duration) GRPCServerOption

WithTimeout 设置服务器超时

func WithWeight

func WithWeight(weight uint32) GRPCServerOption

WithWeight 设置服务权重

type Server

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

Server 是gRPC服务器

func NewServer

func NewServer(opts ...ServerOption) *Server

NewServer 创建gRPC服务器

func (*Server) Endpoint

func (s *Server) Endpoint() (*url.URL, error)

Endpoint 返回gRPC服务器的端点

func (*Server) RegisterService

func (s *Server) RegisterService(sd *grpc.ServiceDesc, ss interface{})

RegisterService 注册gRPC服务

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start 启动gRPC服务器

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop 停止gRPC服务器

func (*Server) UseMiddleware

func (s *Server) UseMiddleware(m ...middleware.Middleware)

UseMiddleware 在gRPC服务器上使用phantasm中间件

type ServerOption

type ServerOption func(*Server)

ServerOption 是gRPC服务器选项

func Address

func Address(address string) ServerOption

Address 设置地址,例如 ":9000", "127.0.0.1:9000" 等

func EidolaServer

func EidolaServer(server *eidola.Server) ServerOption

EidolaServer 设置Eidola服务器

func Logger

func Logger(logger log.Logger) ServerOption

Logger 设置日志记录器

func Name

func Name(name string) ServerOption

Name 设置服务名称

func Network

func Network(network string) ServerOption

Network 设置网络类型,例如 "tcp", "tcp4", "tcp6", "unix" 或 "unixpacket"

func Options

func Options(opts ...grpc.ServerOption) ServerOption

Options 添加grpc服务器选项

func TLSConfig

func TLSConfig(c *tls.Config) ServerOption

TLSConfig 设置TLS配置

func Timeout

func Timeout(timeout time.Duration) ServerOption

Timeout 设置超时时间

func WithStreamServerInterceptors

func WithStreamServerInterceptors(interceptors ...grpc.StreamServerInterceptor) ServerOption

WithStreamServerInterceptors 添加gRPC流拦截器选项

func WithUnaryServerInterceptors

func WithUnaryServerInterceptors(interceptors ...grpc.UnaryServerInterceptor) ServerOption

WithUnaryServerInterceptors 添加gRPC一元拦截器选项

Jump to

Keyboard shortcuts

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