Documentation ¶
Index ¶
- Constants
- Variables
- func EventLoggingUnaryServerInterceptor(options map[string]interface{}) grpc.UnaryServerInterceptor
- func MetricsUnaryServerInterceptor(options map[string]interface{}) grpc.UnaryServerInterceptor
- func New(spf ServerProviderFunc) service.ModuleProvider
- func PayloadUnaryClientInterceptor(options map[string]interface{}) grpc.UnaryClientInterceptor
- func PayloadUnaryServerInterceptor(options map[string]interface{}) grpc.UnaryServerInterceptor
- func PayloadUnaryServerInterceptorWithUUID(options map[string]interface{}) grpc.UnaryServerInterceptor
- func RecoveryUnaryServerInterceptor(options map[string]interface{}) grpc.UnaryServerInterceptor
- func RetryClientInterceptor(options map[string]interface{}) grpc.UnaryClientInterceptor
- func TagUnaryClientInterceptor(options map[string]interface{}) grpc.UnaryClientInterceptor
- func TagUnaryServerInterceptor(options map[string]interface{}) grpc.UnaryServerInterceptor
- func TracerClientInterceptor(options map[string]interface{}) grpc.UnaryClientInterceptor
- func TracerUnaryServerInterceptor(options map[string]interface{}) grpc.UnaryServerInterceptor
- func ZapUnaryClientInterceptor(options map[string]interface{}) grpc.UnaryClientInterceptor
- func ZapUnaryServerInterceptor(options map[string]interface{}) grpc.UnaryServerInterceptor
- type ConnManager
- type Dialer
- type DialerOptions
- type GRPCServer
- type ModuleConfig
- type Options
- type ServerProviderFunc
- type ServiceDialer
- type UnaryClientInterceptor
- type UnaryClientMiddleware
- type UnaryClientMiddlewareName
- type UnaryServerInterceptor
- type UnaryServerMiddleware
- type UnaryServerMiddlewareName
- type UnaryServerMiddlewares
Constants ¶
const ( UnaryServerMiddlewareZapLog UnaryServerMiddlewareName = "Zaplog" UnaryServerMiddlewarePayloadLogger UnaryServerMiddlewareName = "PayloadLogger" UnaryServerMiddlewareTag UnaryServerMiddlewareName = "Tag" UnaryServerMiddlewareEventLogger UnaryServerMiddlewareName = "EventLogger" UnaryServerMiddlewareMetrics UnaryServerMiddlewareName = "Metrics" UnaryServerMiddlewareTracer UnaryServerMiddlewareName = "Tracer" UnaryServerMiddlewareRecovery UnaryServerMiddlewareName = "Recovery" UnaryClientMiddlewareZaplog UnaryClientMiddlewareName = "Zaplog" UnaryClientMiddlewarePayloadLogger UnaryClientMiddlewareName = "PayloadLogger" UnaryClientMiddlewareTag UnaryClientMiddlewareName = "Tag" UnaryClientMiddlewareRetry UnaryClientMiddlewareName = "Retry" UnaryClientMiddlewareTracer UnaryClientMiddlewareName = "Tracer" )
Variables ¶
var ( // DefaultOptions is the default options used by grpc module DefaultOptions = Options{ UnaryServerMiddlewares: []UnaryServerMiddleware{ { Name: UnaryServerMiddlewareZapLog, Interceptor: ZapUnaryServerInterceptor, }, { Name: UnaryServerMiddlewarePayloadLogger, Interceptor: PayloadUnaryServerInterceptor, }, { Name: UnaryServerMiddlewareTag, Interceptor: TagUnaryServerInterceptor, }, { Name: UnaryServerMiddlewareEventLogger, Interceptor: EventLoggingUnaryServerInterceptor, }, { Name: UnaryServerMiddlewareMetrics, Interceptor: MetricsUnaryServerInterceptor, }, { Name: UnaryServerMiddlewareTracer, Interceptor: TracerUnaryServerInterceptor, }, { Name: UnaryServerMiddlewareRecovery, Interceptor: RecoveryUnaryServerInterceptor, }, }, UnaryClientMiddlewares: []UnaryClientMiddleware{ { Name: UnaryClientMiddlewareZaplog, Interceptor: ZapUnaryClientInterceptor, }, { Name: UnaryClientMiddlewarePayloadLogger, Interceptor: PayloadUnaryClientInterceptor, }, { Name: UnaryClientMiddlewareTag, Interceptor: TagUnaryClientInterceptor, }, { Name: UnaryClientMiddlewareRetry, Interceptor: RetryClientInterceptor, }, { Name: UnaryClientMiddlewareTracer, Interceptor: TracerClientInterceptor, }, }, } )
Functions ¶
func EventLoggingUnaryServerInterceptor ¶
func EventLoggingUnaryServerInterceptor(options map[string]interface{}) grpc.UnaryServerInterceptor
func MetricsUnaryServerInterceptor ¶
func MetricsUnaryServerInterceptor(options map[string]interface{}) grpc.UnaryServerInterceptor
func New ¶
func New(spf ServerProviderFunc) service.ModuleProvider
func PayloadUnaryClientInterceptor ¶
func PayloadUnaryClientInterceptor(options map[string]interface{}) grpc.UnaryClientInterceptor
func PayloadUnaryServerInterceptor ¶
func PayloadUnaryServerInterceptor(options map[string]interface{}) grpc.UnaryServerInterceptor
func PayloadUnaryServerInterceptorWithUUID ¶
func PayloadUnaryServerInterceptorWithUUID(options map[string]interface{}) grpc.UnaryServerInterceptor
func RecoveryUnaryServerInterceptor ¶
func RecoveryUnaryServerInterceptor(options map[string]interface{}) grpc.UnaryServerInterceptor
func RetryClientInterceptor ¶
func RetryClientInterceptor(options map[string]interface{}) grpc.UnaryClientInterceptor
func TagUnaryClientInterceptor ¶
func TagUnaryClientInterceptor(options map[string]interface{}) grpc.UnaryClientInterceptor
func TagUnaryServerInterceptor ¶
func TagUnaryServerInterceptor(options map[string]interface{}) grpc.UnaryServerInterceptor
func TracerClientInterceptor ¶
func TracerClientInterceptor(options map[string]interface{}) grpc.UnaryClientInterceptor
func TracerUnaryServerInterceptor ¶
func TracerUnaryServerInterceptor(options map[string]interface{}) grpc.UnaryServerInterceptor
func ZapUnaryClientInterceptor ¶
func ZapUnaryClientInterceptor(options map[string]interface{}) grpc.UnaryClientInterceptor
func ZapUnaryServerInterceptor ¶
func ZapUnaryServerInterceptor(options map[string]interface{}) grpc.UnaryServerInterceptor
Types ¶
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
ConnManager caches grpc connection
func NewConnManager ¶
func NewConnManager(dialer *Dialer) *ConnManager
NewConnManager create ConnManager from dialer
func (*ConnManager) Dial ¶
func (cm *ConnManager) Dial(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
Dial to create a grpc ClientConn by providing fx service path & other filter options
func (*ConnManager) DialWithSelector ¶
func (cm *ConnManager) DialWithSelector(ctx context.Context, serviceName string, selector resolver.Selector, opts ...grpc.DialOption) (*grpc.ClientConn, error)
DialWithSelector to create a grpc ClientConn by providing fx service path & other filter options
type Dialer ¶
type Dialer struct { HostName string EtcdClient *etcd.Client Logger *zap.Logger Tracer opentracing.Tracer UnaryClientMiddlewares []UnaryClientMiddleware // EnableTLS will turn on tls support while connecting to grpc server EnableTLS bool // CAFile is root cert file path // that clients use when verifying server certificates. // if set to empty, will use host's root CA set CAFile string // ServerName is used to determine grpc server name is same in certification // used with EnableTLS // when empty, will use name in certification to compare with ServerName string // EnableClientAuth enable tls bot authentication support at bot side // ref to https://blog.cloudflare.com/introducing-tls-client-auth/ EnableClientAuth bool // CertFile used with EnableClientAuth for tls bot authentication support CertFile string // KeyFile used with EnableClientAuth for tls bot authentication support KeyFile string }
func NewDialer ¶
func NewDialer(opts DialerOptions) (*Dialer, error)
func (*Dialer) DialService ¶
func (d *Dialer) DialService(ctx context.Context, servicePath string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
DialService used to dial to service with specific ServiceDialerOptions
could provide metadata matcher in ServiceDialerOptions servicePath: "/" + hostName + "/" + moduleName
func (*Dialer) DialWithSelector ¶
func (d *Dialer) DialWithSelector(ctx context.Context, target string, selector resolver.Selector, opts ...grpc.DialOption) (*grpc.ClientConn, error)
DialWithSelector is core method to create grpc.ClientConn
it is maybe changed in the future, don't rely on this method
type DialerOptions ¶
type DialerOptions struct { EtcdClient *etcd.Client Logger *zap.Logger Tracer opentracing.Tracer UnaryClientMiddlewares []UnaryClientMiddleware // EnableTLS will turn on tls support while connecting to grpc server EnableTLS bool // CAFile is root cert file path // that clients use when verifying server certificates. // if set to empty, will use host's root CA set CAFile string // ServerName is used to determine grpc server name is same in certification // used with EnableTLS // when empty, will use name in certification to compare with ServerName string // EnableClientAuth enable tls bot authentication support at bot side // ref to https://blog.cloudflare.com/introducing-tls-client-auth/ EnableClientAuth bool // CertFile used with EnableClientAuth for tls bot authentication support CertFile string // KeyFile used with EnableClientAuth for tls bot authentication support KeyFile string }
type GRPCServer ¶
nolint: revive
nolint explain, the GRPCServer class is used for a long time , could not change that name
implement service.ModuleServer Serve method to run an internal loop implement service.ModuleCloser Close method to release resources or connection while app exit
type ModuleConfig ¶
type ModuleConfig struct { modules.ModuleConfig `mapstructure:",squash"` CloseTimeout int64 `mapstructure:"close_timeout"` }
type Options ¶
type Options struct { // UnaryServerMiddlewares could be used to customize grpc unary server interceptors // grpc server loader will use UnaryServerMiddleware in order // STRONGLY recommended don't change the default order of interceptors, the internal order maybe changed without notification UnaryServerMiddlewares []UnaryServerMiddleware // UnaryClientMiddlewares could be used to customize grpc unary bot interceptors // grpc bot loader will use UnaryClientMiddleware in order // STRONGLY recommended don't change the default order of interceptors, the internal order maybe changed without notification UnaryClientMiddlewares []UnaryClientMiddleware }
func (*Options) AddUnaryClientMiddlewareBefore ¶
func (o *Options) AddUnaryClientMiddlewareBefore(name UnaryClientMiddlewareName, middleware UnaryClientMiddleware)
AddUnaryClientMiddlewareBefore add an UnaryClientMiddleware just before named middleware
func (*Options) AddUnaryServerMiddlewareBefore ¶
func (o *Options) AddUnaryServerMiddlewareBefore(name UnaryServerMiddlewareName, middleware UnaryServerMiddleware)
AddUnaryServerMiddlewareBefore add an UnaryServerMiddleware just before named middleware
type ServerProviderFunc ¶
type ServerProviderFunc func(driver service.ModuleDriver) (GRPCServer, error)
passing parameter should be service.ScopedHost type, but now for compatible reason , it is service.Host now
type ServiceDialer ¶
type ServiceDialer interface { DialService(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error) DialWithSelector(ctx context.Context, target string, selector resolver.Selector, opts ...grpc.DialOption) (*grpc.ClientConn, error) }
ServiceDialer is the interface to dial to service
type UnaryClientInterceptor ¶
type UnaryClientInterceptor func(options map[string]interface{}) grpc.UnaryClientInterceptor
type UnaryClientMiddleware ¶
type UnaryClientMiddleware struct { // Key is used to define certain server interceptor // just for reference , and for human reading Name UnaryClientMiddlewareName // Interceptor is the customized version of interceptor // if set to nil , bot loader will skip load this interceptor Interceptor UnaryClientInterceptor }
type UnaryClientMiddlewareName ¶
type UnaryClientMiddlewareName string
type UnaryServerInterceptor ¶
type UnaryServerInterceptor func(options map[string]interface{}) grpc.UnaryServerInterceptor
type UnaryServerMiddleware ¶
type UnaryServerMiddleware struct { // Name is used to define certain server interceptor // just for reference, and for human reading Name UnaryServerMiddlewareName // Interceptor is the customized version of interceptor // if set to nil , server loader will skip load this interceptor Interceptor UnaryServerInterceptor }
type UnaryServerMiddlewareName ¶
type UnaryServerMiddlewareName string
type UnaryServerMiddlewares ¶
type UnaryServerMiddlewares []UnaryServerMiddleware