grpcserver

package
v1.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithVirtualStreamBaseServer

func WithVirtualStreamBaseServer(server *BaseGrpcServer) initVirtualStream

WithVirtualStreamBaseServer 设置 BaseGrpcServer

func WithVirtualStreamLogger

func WithVirtualStreamLogger(log *commonlog.Scope) initVirtualStream

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

type BaseGrpcServer struct {
	OpenMethod map[string]bool
	// contains filtered or unexported fields
}

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

func NewCache

func NewCache(options map[string]interface{}, cacheType []string) (Cache, error)

NewCache Component a PB cache pool

type CacheObject

type CacheObject struct {
	// OriginVal
	OriginVal proto.Message

	// CacheType
	CacheType string
	// Key
	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 WithLogger

func WithLogger(log *commonlog.Scope) InitOption

WithLogger

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

func WithProtobufCache

func WithProtobufCache(cache Cache) InitOption

WithProtobufCache

func WithProtocol

func WithProtocol(protocol string) InitOption

WithProtocol

type InitServer

type InitServer func(*grpc.Server) error

InitServer BaseGrpcServer.Run 中回调函数的定义

type MessageToCache

type MessageToCache func(m interface{}) *CacheObject

MessageToCache

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.

Directories

Path Synopsis
v1

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL