Documentation
¶
Index ¶
- Variables
- func NewClient(target string, opt ...ClientOption) (*client, error)
- func NewServer(opt ...ServerOption) *server
- type CallOption
- type Client
- type ClientConn
- type ClientOption
- func WithChainStreamInterceptor(Interceptors ...StreamClientInterceptor) ClientOption
- func WithChainUnaryInterceptor(Interceptors ...UnaryClientInterceptor) ClientOption
- func WithGRPCOptions(opts ...DialOption) ClientOption
- func WithStreamInterceptor(interceptor StreamClientInterceptor) ClientOption
- func WithUnaryInterceptor(interceptor UnaryClientInterceptor) ClientOption
- type ClientStream
- type DialOption
- type GRPCStreamDesc
- type Handler
- type Implementation
- type Interceptor
- func (i *Interceptor) ChainStreamInterceptor(ints ...StreamServerInterceptor) *Interceptor
- func (i *Interceptor) ChainUnaryInterceptor(ints ...UnaryServerInterceptor) *Interceptor
- func (i *Interceptor) StreamClientInterceptor() StreamClientInterceptor
- func (i *Interceptor) StreamInterceptor() StreamServerInterceptor
- func (i *Interceptor) UnaryClientInterceptor() UnaryClientInterceptor
- func (i *Interceptor) UnaryInterceptor() UnaryServerInterceptor
- func (i *Interceptor) WithChainStreamInterceptor(ints ...StreamClientInterceptor) *Interceptor
- func (i *Interceptor) WithChainUnaryInterceptor(ints ...UnaryClientInterceptor) *Interceptor
- type Server
- type ServerOption
- func ChainStreamInterceptor(ints ...StreamServerInterceptor) ServerOption
- func ChainUnaryInterceptor(ints ...UnaryServerInterceptor) ServerOption
- func Codec(codecs ...encoding.Codec) ServerOption
- func Compression(name string, decompressor compress.Decompressor, ...) ServerOption
- func CompressionMinBytes(n int) ServerOption
- func Creds(c credentials.TransportCredentials) ServerOption
- func EnableTracing() ServerOption
- func GlobalHandler(h func(next http.Handler) http.Handler) ServerOption
- func IdleTimeout(d time.Duration) ServerOption
- func MaxConcurrentStreams(n uint32) ServerOption
- func MaxRecvMsgSize(n int) ServerOption
- func MaxSendMsgSize(n int) ServerOption
- func ReadTimeout(d time.Duration) ServerOption
- func StreamInterceptor(i StreamServerInterceptor) ServerOption
- func UnaryInterceptor(i UnaryServerInterceptor) ServerOption
- func UnknownHandler(h http.Handler) ServerOption
- func WriteTimeout(d time.Duration) ServerOption
- type ServerStream
- type StreamClientInterceptor
- type StreamHandler
- type StreamServerInfo
- type StreamServerInterceptor
- type Streamer
- type UnaryClientInterceptor
- type UnaryHandler
- type UnaryInvoker
- type UnaryServerInfo
- type UnaryServerInterceptor
Constants ¶
This section is empty.
Variables ¶
var (
ErrServerStopped = errors.New("srpc: the server has been stopped")
)
Functions ¶
func NewClient ¶
func NewClient(target string, opt ...ClientOption) (*client, error)
func NewServer ¶
func NewServer(opt ...ServerOption) *server
Types ¶
type CallOption ¶
type CallOption = grpc.CallOption
type Client ¶
type Client interface { grpc.ClientConnInterface }
type ClientConn ¶
type ClientConn = grpc.ClientConn
type ClientOption ¶
type ClientOption func(o *clientOptions)
func WithChainStreamInterceptor ¶
func WithChainStreamInterceptor(Interceptors ...StreamClientInterceptor) ClientOption
func WithChainUnaryInterceptor ¶
func WithChainUnaryInterceptor(Interceptors ...UnaryClientInterceptor) ClientOption
func WithGRPCOptions ¶
func WithGRPCOptions(opts ...DialOption) ClientOption
func WithStreamInterceptor ¶
func WithStreamInterceptor(interceptor StreamClientInterceptor) ClientOption
func WithUnaryInterceptor ¶
func WithUnaryInterceptor(interceptor UnaryClientInterceptor) ClientOption
type ClientStream ¶
type ClientStream = grpc.ClientStream
type DialOption ¶
type DialOption = grpc.DialOption
type GRPCStreamDesc ¶
type GRPCStreamDesc = grpc.StreamDesc
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is an HTTP handler that serves RPC requests.
func (*Handler) ServeHTTP ¶
func (h *Handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request)
ServeHTTP implements http.Handler.
type Implementation ¶
type Implementation func(ctx context.Context, stream protocol.StreamingHandlerConn) error
Implementation is a function type that handles an RPC call with the given context and stream.
type Interceptor ¶
type Interceptor struct {
// contains filtered or unexported fields
}
Interceptor manages the RPC interceptor chains for both server and client-side interceptors, supporting both unary and streaming modes. It provides chainable methods to add multiple interceptors that will be executed in sequence.
Interceptors follow an "onion model" execution pattern: - For servers: The first added interceptor processes the request first and the response last - For clients: The first added interceptor processes outgoing messages first and incoming messages last
Request flow visualization:
client.Send() client.Receive() | ^ v | A --- --- A B --- --- B : ... ... : Y --- --- Y Z --- --- Z | ^ v | = = = = = = = = = = = = = = = = network = = = = = = = = = = = = = = = = | ^ v | A --- --- A B --- --- B : ... ... : Y --- --- Y Z --- --- Z | ^ v | handler.Receive() handler.Send() | ^ | | '-> handler logic >-'
Note: In clients, Send handles request messages and Receive handles response messages. For handlers, it's the reverse. Depending on your interceptor's logic, you may need to wrap different methods in clients versus servers.
Interceptors are commonly used for implementing cross-cutting concerns like logging, authentication, error handling, metrics collection, and tracing.
func (*Interceptor) ChainStreamInterceptor ¶
func (i *Interceptor) ChainStreamInterceptor(ints ...StreamServerInterceptor) *Interceptor
ChainStreamInterceptor adds stream server interceptors to the chain. See grpc.ChainStreamInterceptor for more details.
func (*Interceptor) ChainUnaryInterceptor ¶
func (i *Interceptor) ChainUnaryInterceptor(ints ...UnaryServerInterceptor) *Interceptor
ChainUnaryInterceptor adds unary server interceptors to the chain. See grpc.ChainUnaryInterceptor for more details.
func (*Interceptor) StreamClientInterceptor ¶
func (i *Interceptor) StreamClientInterceptor() StreamClientInterceptor
func (*Interceptor) StreamInterceptor ¶
func (i *Interceptor) StreamInterceptor() StreamServerInterceptor
func (*Interceptor) UnaryClientInterceptor ¶
func (i *Interceptor) UnaryClientInterceptor() UnaryClientInterceptor
func (*Interceptor) UnaryInterceptor ¶
func (i *Interceptor) UnaryInterceptor() UnaryServerInterceptor
func (*Interceptor) WithChainStreamInterceptor ¶
func (i *Interceptor) WithChainStreamInterceptor(ints ...StreamClientInterceptor) *Interceptor
WithChainStreamInterceptor adds stream client interceptors to the chain. See grpc.WithChainStreamInterceptor for more details.
func (*Interceptor) WithChainUnaryInterceptor ¶
func (i *Interceptor) WithChainUnaryInterceptor(ints ...UnaryClientInterceptor) *Interceptor
WithChainUnaryInterceptor adds unary client interceptors to the chain. See WithChainUnaryInterceptor for more details.
type Server ¶
type Server interface { grpc.ServiceRegistrar reflection.GRPCServer Serve(l net.Listener) error Stop() GracefulStop() Handle(pattern string, handler http.Handler) }
type ServerOption ¶
type ServerOption func(o *serverOptions)
func ChainStreamInterceptor ¶
func ChainStreamInterceptor(ints ...StreamServerInterceptor) ServerOption
ChainStreamInterceptor returns a ServerOption that specifies the chained interceptor for stream RPCs. The first interceptor will be the outer most, while the last interceptor will be the inner most wrapper around the real call. All stream interceptors added by this method will be chained.
func ChainUnaryInterceptor ¶
func ChainUnaryInterceptor(ints ...UnaryServerInterceptor) ServerOption
ChainUnaryInterceptor returns a ServerOption that specifies the chained interceptor for unary RPCs. The first interceptor will be the outer most, while the last interceptor will be the inner most wrapper around the real call. All unary interceptors added by this method will be chained.
func Codec ¶
func Codec(codecs ...encoding.Codec) ServerOption
Codec returns a ServerOption that sets the codecs for the server.
func Compression ¶
func Compression(name string, decompressor compress.Decompressor, compressor compress.Compressor) ServerOption
Compression returns a ServerOption that sets the compression algorithm
func CompressionMinBytes ¶
func CompressionMinBytes(n int) ServerOption
CompressionMinBytes returns a ServerOption that sets the minimum number of bytes for compression to be applied. This is useful for tuning the performance of the server. If not set, the default value is 0, which means no minimum size. Compression will be applied to all messages.
func Creds ¶
func Creds(c credentials.TransportCredentials) ServerOption
Creds returns a ServerOption that sets credentials for server connections.
func EnableTracing ¶
func EnableTracing() ServerOption
EnableTracing returns a ServerOption that enables tracing for the server. This is useful for debugging and monitoring the server's performance. If not set, tracing is disabled by default.
func GlobalHandler ¶ added in v0.0.3
func GlobalHandler(h func(next http.Handler) http.Handler) ServerOption
GlobalHandler returns a ServerOption that sets the global handler for the server. This handler will be used for all requests that do not match any registered service or method.
func IdleTimeout ¶
func IdleTimeout(d time.Duration) ServerOption
IdleTimeout returns a ServerOption that sets the idle timeout for the server.
func MaxConcurrentStreams ¶
func MaxConcurrentStreams(n uint32) ServerOption
MaxConcurrentStreams returns a ServerOption that will apply a limit on the number of concurrent streams to each ServerTransport.
func MaxRecvMsgSize ¶
func MaxRecvMsgSize(n int) ServerOption
MaxRecvMsgSize returns a ServerOption to set the max message size in bytes the server can receive. If this is not set, gRPC uses the default 4MB.
func MaxSendMsgSize ¶
func MaxSendMsgSize(n int) ServerOption
MaxSendMsgSize returns a ServerOption to set the max message size in bytes the server can send. If this is not set, gRPC uses the default `math.MaxInt32`.
func ReadTimeout ¶
func ReadTimeout(d time.Duration) ServerOption
ReadTimeout returns a ServerOption that sets the read timeout for the server.
func StreamInterceptor ¶
func StreamInterceptor(i StreamServerInterceptor) ServerOption
StreamInterceptor returns a ServerOption that sets the StreamServerInterceptor for the server.
func UnaryInterceptor ¶
func UnaryInterceptor(i UnaryServerInterceptor) ServerOption
UnaryInterceptor returns a ServerOption that sets the UnaryServerInterceptor for the server.
func UnknownHandler ¶
func UnknownHandler(h http.Handler) ServerOption
UnknownHandler returns a ServerOption that sets the handler for unknown requests. This is useful for handling requests that do not match any registered service or method. The handler should be a http.Handler that can handle the request and return a response. If not set, the server will return a 404 Not Found response for unknown requests.
func WriteTimeout ¶
func WriteTimeout(d time.Duration) ServerOption
WriteTimeout returns a ServerOption that sets the write timeout for the server.
type ServerStream ¶
type ServerStream = grpc.ServerStream
type StreamClientInterceptor ¶
type StreamClientInterceptor = grpc.StreamClientInterceptor
type StreamHandler ¶
type StreamHandler = grpc.StreamHandler
type StreamServerInfo ¶
type StreamServerInfo = grpc.StreamServerInfo
type StreamServerInterceptor ¶
type StreamServerInterceptor = grpc.StreamServerInterceptor
type UnaryClientInterceptor ¶
type UnaryClientInterceptor = grpc.UnaryClientInterceptor
type UnaryHandler ¶
type UnaryHandler = grpc.UnaryHandler
type UnaryInvoker ¶
type UnaryInvoker = grpc.UnaryInvoker
type UnaryServerInfo ¶
type UnaryServerInfo = grpc.UnaryServerInfo
type UnaryServerInterceptor ¶
type UnaryServerInterceptor = grpc.UnaryServerInterceptor
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
proto
module
|
|
internal
|
|
srpcsync
Package srpcsync implements additional synchronization primitives built upon the sync package.
|
Package srpcsync implements additional synchronization primitives built upon the sync package. |
Package mem provides utilities that facilitate memory reuse in byte slices that are used as buffers.
|
Package mem provides utilities that facilitate memory reuse in byte slices that are used as buffers. |