Documentation
¶
Overview ¶
Package grpc provides framework bootstrap and assembly helpers for gRPC services in gorp. This file assembles and runs the gRPC service alongside or independent of the HTTP mainline. Builds a reusable runtime carrying container, gRPC server, config, and logger.
本包提供 gorp 框架的 gRPC 服务启动装配辅助能力。 本文件装配并运行与 HTTP 主线解耦的 gRPC 服务。 构建复用型 runtime 对象,统一承载 container、gRPC server、config、logger 能力。
Index ¶
- func BootGRPCService(serviceName string, opts GRPCServiceOptions, ...) (retErr error)
- func RunGRPC(c runtimecontract.Container, logger observabilitycontract.Logger) error
- func StartGRPCServer(c runtimecontract.Container, logger observabilitycontract.Logger) (transportcontract.RPCServer, error)
- type GRPCServiceOptions
- type GRPCServiceRuntime
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BootGRPCService ¶
func BootGRPCService(serviceName string, opts GRPCServiceOptions, setup func(*GRPCServiceRuntime) error) (retErr error)
BootGRPCService assembles, configures, and runs the standalone gRPC service. This is the gRPC counterpart of BootHTTPService, used when gRPC runs independently.
BootGRPCService 装配、配置并运行独立的 gRPC 服务。 这是 BootHTTPService 的 gRPC 对称入口,在 gRPC 独立运行时使用。
func RunGRPC ¶
func RunGRPC(c runtimecontract.Container, logger observabilitycontract.Logger) error
RunGRPC runs the gRPC service through the host capability when present. Falls back to direct gRPC run mode when host is unavailable.
RunGRPC 优先通过 host 能力运行 gRPC 服务。 当 host 能力不可用时,回退到 gRPC 直跑模式。
func StartGRPCServer ¶
func StartGRPCServer(c runtimecontract.Container, logger observabilitycontract.Logger) (transportcontract.RPCServer, error)
StartGRPCServer starts the gRPC server from the container when the container has a GRPCServerRegistrar bound. Returns the RPCServer if started, nil otherwise. This is used by the HTTP bootstrap to auto-start gRPC alongside HTTP in microservice mode.
StartGRPCServer 在容器中存在 GRPCServerRegistrar 时启动 gRPC 服务器。 返回启动的 RPCServer;如果容器中没有 gRPC 能力则返回 nil。 用于 HTTP bootstrap 在微服务模式下自动与 HTTP 一起启动 gRPC。
Types ¶
type GRPCServiceOptions ¶
type GRPCServiceOptions struct {
// ExtraProviders 是额外追加到容器中的 provider 列表。
//
// ExtraProviders 是额外追加到容器中的 provider 列表。
ExtraProviders []runtimecontract.ServiceProvider
// GovernanceMode 显式声明运行时治理模式。
//
// GovernanceMode 显式声明运行时治理模式。
GovernanceMode string
// GovernanceDisable 显式关闭的默认治理能力列表。
//
// GovernanceDisable 显式关闭的默认治理能力列表。
GovernanceDisable []string
// GovernanceEnable 显式开启的默认关闭治理能力列表。
//
// GovernanceEnable 显式开启的默认关闭治理能力列表。
GovernanceEnable []string
// GovernanceProviders 显式覆盖的治理 provider backend 映射。
//
// GovernanceProviders 显式覆盖的治理 provider backend 映射。
GovernanceProviders map[string]string
}
GRPCServiceOptions describes the bootstrap options for the gRPC service mainline.
GRPCServiceOptions 描述 gRPC 服务主线的 bootstrap 选项。
type GRPCServiceRuntime ¶
type GRPCServiceRuntime struct {
// App 是框架 Application 实例。
//
// App 是框架 Application 实例。
App *framework.Application
// Container 是运行时依赖注入容器。
//
// Container 是运行时依赖注入容器。
Container runtimecontract.Container
// Logger 是日志能力实例。
//
// Logger 是日志能力实例。
Logger observabilitycontract.Logger
// Server 是底层 gRPC 服务器实例,供用户在 setup 阶段注册 proto 服务。
//
// Server 是底层 gRPC 服务器实例,供用户在 setup 阶段注册 proto 服务。
Server *grpc.Server
// Registrar 是 gRPC 服务注册器,提供 RegisterProto 和 Server 方法。
//
// Registrar 是 gRPC 服务注册器,提供 RegisterProto 和 Server 方法。
Registrar transportcontract.GRPCServerRegistrar
// Config 是配置能力实例。
//
// Config 是配置能力实例。
Config datacontract.Config
// ServiceName 是当前服务名。
//
// ServiceName 是当前服务名。
ServiceName string
// GovernanceMode 是生效的治理模式。
//
// GovernanceMode 是生效的治理模式。
GovernanceMode resiliencecontract.GovernanceMode
// GovernanceSummary 是治理摘要信息。
//
// GovernanceSummary 是治理摘要信息。
GovernanceSummary bootstrap.GovernanceSummary
}
GRPCServiceRuntime carries the assembled gRPC runtime state used during startup callbacks.
GRPCServiceRuntime 承载启动回调阶段使用的 gRPC runtime 状态。
func NewGRPCServiceRuntime ¶
func NewGRPCServiceRuntime(serviceName string, opts GRPCServiceOptions) (rt *GRPCServiceRuntime, retErr error)
NewGRPCServiceRuntime builds the default gRPC runtime without starting the server.
NewGRPCServiceRuntime 构建默认 gRPC runtime,但不启动服务。