Documentation
¶
Index ¶
- type Option
- func WithAutoServiceDiscovery(registries []discover.Registry, sdOpts ...ServiceDiscoveryOption) Option
- func WithEnvironment(env string) Option
- func WithGracefulStopTimeout(d time.Duration) Option
- func WithGrpcServerOptions(opts ...grpc.ServerOption) Option
- func WithGrpcServerStreamInterceptor(interceptors ...grpc.StreamServerInterceptor) Option
- func WithGrpcServerUnaryInterceptor(interceptors ...grpc.UnaryServerInterceptor) Option
- func WithMetadata(md map[string]string) Option
- func WithPriority(priority int) Option
- func WithRegionInfo(region, zone, campus string) Option
- func WithServiceName(name string) Option
- func WithTLS(certFile, keyFile string) Option
- func WithTLSConfig(cfg *tls.Config) Option
- func WithVersion(version string) Option
- func WithWeight(weight int) Option
- type ProtoServiceInfo
- type ProtoServiceWrapper
- type Server
- type ServiceDiscovery
- type ServiceDiscoveryOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Server)
func WithAutoServiceDiscovery ¶
func WithAutoServiceDiscovery(registries []discover.Registry, sdOpts ...ServiceDiscoveryOption) Option
WithAutoServiceDiscovery 启用自动服务发现,为每个protobuf服务单独注册。 可通过 sdOpts 传入 WithInternalServices() 等服务发现选项。
func WithGracefulStopTimeout ¶
WithGracefulStopTimeout 设置 GracefulStop 的最长等待时间,超时后强制 Stop。 默认 30s。
func WithGrpcServerOptions ¶
func WithGrpcServerOptions(opts ...grpc.ServerOption) Option
func WithGrpcServerStreamInterceptor ¶
func WithGrpcServerStreamInterceptor(interceptors ...grpc.StreamServerInterceptor) Option
func WithGrpcServerUnaryInterceptor ¶
func WithGrpcServerUnaryInterceptor(interceptors ...grpc.UnaryServerInterceptor) Option
func WithMetadata ¶
func WithRegionInfo ¶
WithRegionInfo 设置地域信息,兼容Polaris
func WithServiceName ¶
func WithTLSConfig ¶
WithTLSConfig 通过自定义 tls.Config 启用 TLS,适合需要 mTLS 或自定义 CA 的场景。
func WithVersion ¶
WithVersion 将服务版本写入 metadata,注册到注册中心后可见,灰度发布时可用于流量路由。
type ProtoServiceInfo ¶
type ProtoServiceInfo struct {
ServiceName string `json:"service_name"`
Methods []string `json:"methods"`
Metadata map[string]string `json:"metadata"`
ServerAddr string `json:"server_addr"`
}
ProtoServiceInfo protobuf服务信息
type ProtoServiceWrapper ¶
type ProtoServiceWrapper struct {
// contains filtered or unexported fields
}
ProtoServiceWrapper 实现discover.Service接口
func (*ProtoServiceWrapper) Addr ¶
func (w *ProtoServiceWrapper) Addr() string
func (*ProtoServiceWrapper) ID ¶
func (w *ProtoServiceWrapper) ID() string
func (*ProtoServiceWrapper) Kind ¶
func (w *ProtoServiceWrapper) Kind() string
func (*ProtoServiceWrapper) Metadata ¶
func (w *ProtoServiceWrapper) Metadata() map[string]string
func (*ProtoServiceWrapper) Name ¶
func (w *ProtoServiceWrapper) Name() string
type ServiceDiscovery ¶
type ServiceDiscovery struct {
// contains filtered or unexported fields
}
ServiceDiscovery 从gRPC Server中读取已注册的服务
func NewServiceDiscovery ¶
func NewServiceDiscovery(server *grpc.Server, registries []discover.Registry, opts ...ServiceDiscoveryOption) *ServiceDiscovery
NewServiceDiscovery 创建服务发现器
func (*ServiceDiscovery) DiscoverServices ¶
func (sd *ServiceDiscovery) DiscoverServices(serverAddr string, baseMetadata map[string]string) error
DiscoverServices 发现gRPC Server中已注册的服务
func (*ServiceDiscovery) RegisterAllServices ¶
func (sd *ServiceDiscovery) RegisterAllServices(ctx context.Context) (wait func(), err error)
RegisterAllServices 注册所有发现的服务,返回一个 wait 函数, 调用方可在 ctx 取消后调用 wait() 确保所有注册 goroutine 已退出。
type ServiceDiscoveryOption ¶
type ServiceDiscoveryOption func(*ServiceDiscovery)
ServiceDiscoveryOption 服务发现选项
func WithInternalServices ¶
func WithInternalServices() ServiceDiscoveryOption
WithInternalServices 将 health check、reflection 等内部服务也注册到服务注册中心