Documentation
¶
Overview ¶
Package server 提供 HTTP/gRPC 服务器抽象。
核心功能:
- HTTP 服务器(基于 Gin)
- gRPC 服务器
- 多路复用(同端口同时支持 HTTP/gRPC)
- 服务器组管理
使用示例:
http := server.NewHTTP(cfg) grpc := server.NewGRPC(cfg) group := server.NewGroup(http, grpc) group.Start(ctx)
Package server 提供统一的服务器抽象
Index ¶
- type GRPCOption
- func WithGRPCAddr(addr string) GRPCOption
- func WithMaxRecvMsgSize(size int) GRPCOption
- func WithMaxSendMsgSize(size int) GRPCOption
- func WithReflection(enable bool) GRPCOption
- func WithStreamInterceptor(i grpc.StreamServerInterceptor) GRPCOption
- func WithUnaryInterceptor(i grpc.UnaryServerInterceptor) GRPCOption
- type GRPCOptions
- type GRPCServer
- func (s *GRPCServer) Addr() string
- func (s *GRPCServer) HealthServer() *health.Server
- func (s *GRPCServer) Name() string
- func (s *GRPCServer) RegisterService(fn func(*grpc.Server))
- func (s *GRPCServer) Server() *grpc.Server
- func (s *GRPCServer) Start(ctx context.Context) error
- func (s *GRPCServer) Stop(ctx context.Context) error
- type Group
- type HTTPServer
- type MultiplexServer
- type Option
- type Options
- type Runnable
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GRPCOption ¶
type GRPCOption func(*GRPCOptions)
GRPCOption gRPC 配置选项
func WithMaxRecvMsgSize ¶
func WithMaxRecvMsgSize(size int) GRPCOption
WithMaxRecvMsgSize 设置最大接收消息大小
func WithMaxSendMsgSize ¶
func WithMaxSendMsgSize(size int) GRPCOption
WithMaxSendMsgSize 设置最大发送消息大小
func WithStreamInterceptor ¶
func WithStreamInterceptor(i grpc.StreamServerInterceptor) GRPCOption
WithStreamInterceptor 添加 Stream 拦截器
func WithUnaryInterceptor ¶
func WithUnaryInterceptor(i grpc.UnaryServerInterceptor) GRPCOption
WithUnaryInterceptor 添加 Unary 拦截器
type GRPCOptions ¶
type GRPCOptions struct {
Options
MaxRecvMsgSize int
MaxSendMsgSize int
EnableReflection bool
Interceptors []grpc.UnaryServerInterceptor
StreamInterceptors []grpc.StreamServerInterceptor
}
GRPCOptions gRPC 服务器配置
type GRPCServer ¶
type GRPCServer struct {
// contains filtered or unexported fields
}
GRPCServer gRPC 服务器
func (*GRPCServer) HealthServer ¶
func (s *GRPCServer) HealthServer() *health.Server
HealthServer 返回健康检查服务器
func (*GRPCServer) RegisterService ¶
func (s *GRPCServer) RegisterService(fn func(*grpc.Server))
RegisterService 注册服务
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group 服务器组,管理多个服务器的生命周期
type HTTPServer ¶
type HTTPServer struct {
// contains filtered or unexported fields
}
HTTPServer HTTP 服务器
func NewHTTPServer ¶
func NewHTTPServer(handler http.Handler, opts ...Option) *HTTPServer
NewHTTPServer 创建 HTTP 服务器
type MultiplexServer ¶
type MultiplexServer struct {
// contains filtered or unexported fields
}
MultiplexServer 多协议复用服务器 (HTTP + gRPC 同端口)
func NewMultiplexServer ¶
func NewMultiplexServer(httpHandler http.Handler, grpcServer *grpc.Server, opts ...Option) *MultiplexServer
NewMultiplexServer 创建多协议复用服务器
type Option ¶
type Option func(*Options)
Option 配置选项函数
func WithShutdownTimeout ¶
WithShutdownTimeout 设置关闭超时
type Options ¶
type Options struct {
Name string
Addr string
ReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
ShutdownTimeout time.Duration
MaxHeaderBytes int
}
Options 通用服务器配置
Click to show internal directories.
Click to hide internal directories.