Documentation ¶
Index ¶
- func ConvertContext(ctx context.Context) context.Context
- func WithVirtualStreamBaseServer(server *BaseGrpcServer) initVirtualStream
- func WithVirtualStreamLogger(log *commonlog.Scope) initVirtualStream
- func WithVirtualStreamMethod(method string) initVirtualStream
- func WithVirtualStreamPostProcessFunc(postprocess PostProcessFunc) initVirtualStream
- func WithVirtualStreamPreProcessFunc(preprocess PreProcessFunc) initVirtualStream
- func WithVirtualStreamServerStream(stream grpc.ServerStream) initVirtualStream
- type BaseGrpcServer
- func (b *BaseGrpcServer) AllowAccess(method string) bool
- func (b *BaseGrpcServer) EnterRatelimit(ip string, method string) uint32
- func (b *BaseGrpcServer) GetPort() uint32
- func (b *BaseGrpcServer) Initialize(ctx context.Context, conf map[string]interface{}, initOptions ...InitOption) error
- func (b *BaseGrpcServer) Restart(initialize func() error, run func(), protocol string, ...) error
- func (b *BaseGrpcServer) Run(errCh chan error, protocol string, initServer InitServer)
- func (b *BaseGrpcServer) Stop(protocol string)
- type Cache
- type CacheObject
- type InitOption
- type InitServer
- type MessageToCache
- type PostProcessFunc
- type PreProcessFunc
- type VirtualStream
- func (v *VirtualStream) Context() context.Context
- func (v *VirtualStream) RecvMsg(m interface{}) error
- func (v *VirtualStream) SendHeader(md metadata.MD) error
- func (v *VirtualStream) SendMsg(m interface{}) error
- func (v *VirtualStream) SetHeader(md metadata.MD) error
- func (v *VirtualStream) SetTrailer(md metadata.MD)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertContext ¶
ConvertContext 将GRPC上下文转换成内部上下文
func WithVirtualStreamBaseServer ¶
func WithVirtualStreamBaseServer(server *BaseGrpcServer) initVirtualStream
WithVirtualStreamBaseServer 设置 BaseGrpcServer
func WithVirtualStreamLogger ¶
WithVirtualStreamLogger 设置 Logger
func WithVirtualStreamMethod ¶
func WithVirtualStreamMethod(method string) initVirtualStream
WithVirtualStreamMethod 设置 method
func WithVirtualStreamPostProcessFunc ¶
func WithVirtualStreamPostProcessFunc(postprocess PostProcessFunc) initVirtualStream
WithVirtualStreamPostProcessFunc 设置 PostProcessFunc
func WithVirtualStreamPreProcessFunc ¶
func WithVirtualStreamPreProcessFunc(preprocess PreProcessFunc) initVirtualStream
WithVirtualStreamPreProcessFunc 设置 PreProcessFunc
func WithVirtualStreamServerStream ¶
func WithVirtualStreamServerStream(stream grpc.ServerStream) initVirtualStream
WithVirtualStreamServerStream 设置 grpc.ServerStream
Types ¶
type BaseGrpcServer ¶
BaseGrpcServer base utilities and functions for gRPC Connector
func (*BaseGrpcServer) AllowAccess ¶
func (b *BaseGrpcServer) AllowAccess(method string) bool
AllowAccess api allow access
func (*BaseGrpcServer) EnterRatelimit ¶
func (b *BaseGrpcServer) EnterRatelimit(ip string, method string) uint32
EnterRatelimit api ratelimit
func (*BaseGrpcServer) GetPort ¶
func (b *BaseGrpcServer) GetPort() uint32
GetPort get the connector listen port value
func (*BaseGrpcServer) Initialize ¶
func (b *BaseGrpcServer) Initialize(ctx context.Context, conf map[string]interface{}, initOptions ...InitOption) error
Initialize init the gRPC server
func (*BaseGrpcServer) Restart ¶
func (b *BaseGrpcServer) Restart( initialize func() error, run func(), protocol string, option map[string]interface{}) error
Restart restart gRPC server
func (*BaseGrpcServer) Run ¶
func (b *BaseGrpcServer) Run(errCh chan error, protocol string, initServer InitServer)
Run server main loop
func (*BaseGrpcServer) Stop ¶
func (b *BaseGrpcServer) Stop(protocol string)
Stop stopping the gRPC server
type Cache ¶
type Cache interface { // Get Get(cacheType string, key string) *CacheObject // Put Put(v *CacheObject) (*CacheObject, bool) }
Cache
type CacheObject ¶
type CacheObject struct { OriginVal proto.Message CacheType string Key string // contains filtered or unexported fields }
CacheObject
func (*CacheObject) GetPreparedMessage ¶
func (c *CacheObject) GetPreparedMessage() *grpc.PreparedMsg
func (*CacheObject) PrepareMessage ¶
func (c *CacheObject) PrepareMessage(stream grpc.ServerStream) error
type InitOption ¶
type InitOption func(svr *BaseGrpcServer)
func WithMessageToCacheObject ¶
func WithMessageToCacheObject(convert MessageToCache) InitOption
WithMessageToCacheObject
func WithModule ¶ added in v1.14.0
func WithModule(bz model.BzModule) InitOption
WithModule set bz module
type PostProcessFunc ¶
type PostProcessFunc func(stream *VirtualStream, m interface{})
PostProcessFunc postprocess function define
type PreProcessFunc ¶
type PreProcessFunc func(stream *VirtualStream, isPrint bool) error
PreProcessFunc preprocess function define
type VirtualStream ¶
type VirtualStream struct { Method string ClientAddress string ClientIP string UserAgent string RequestID string Code int StartTime time.Time // contains filtered or unexported fields }
VirtualStream 虚拟Stream 继承ServerStream
func (*VirtualStream) Context ¶
func (v *VirtualStream) Context() context.Context
Context returns the context for this stream.
func (*VirtualStream) RecvMsg ¶
func (v *VirtualStream) RecvMsg(m interface{}) error
RecvMsg blocks until it receives a message into m or the stream is done. It returns io.EOF when the client has performed a CloseSend. On any non-EOF error, the stream is aborted and the error contains the RPC status.
It is safe to have a goroutine calling SendMsg and another goroutine calling RecvMsg on the same stream at the same time, but it is not safe to call RecvMsg on the same stream in different goroutines.
func (*VirtualStream) SendHeader ¶
func (v *VirtualStream) SendHeader(md metadata.MD) error
SendHeader sends the header metadata. The provided md and headers set by SetHeader() will be sent. It fails if called multiple times.
func (*VirtualStream) SendMsg ¶
func (v *VirtualStream) SendMsg(m interface{}) error
SendMsg sends a message. On error, SendMsg aborts the stream and the error is returned directly.
SendMsg blocks until:
- There is sufficient flow control to schedule m with the transport, or
- The stream is done, or
- The stream breaks.
SendMsg does not wait until the message is received by the client. An untimely stream closure may result in lost messages.
It is safe to have a goroutine calling SendMsg and another goroutine calling RecvMsg on the same stream at the same time, but it is not safe to call SendMsg on the same stream in different goroutines.
func (*VirtualStream) SetHeader ¶
func (v *VirtualStream) SetHeader(md metadata.MD) error
SetHeader sets the header metadata. It may be called multiple times. When call multiple times, all the provided metadata will be merged. All the metadata will be sent out when one of the following happens:
- ServerStream.SendHeader() is called;
- The first response is sent out;
- An RPC status is sent out (error or success).
func (*VirtualStream) SetTrailer ¶
func (v *VirtualStream) SetTrailer(md metadata.MD)
SetTrailer sets the trailer metadata which will be sent with the RPC status. When called more than once, all the provided metadata will be merged.