Documentation ¶
Overview ¶
Package grpc provides generic functionality for grpc
Package grpc provides generic functionality for grpc ¶
Copyright (C) 2019-2024 vdaas.org vald team <vald@vdaas.org>
Licensed under the Apache License, Version 2.0 (the "License"); You may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package grpc provides generic functionality for grpc ¶
Package grpc provides generic functionality for grpc ¶
Package grpc provides generic functionality for grpc ¶
Package grpc provides generic functionality for grpc ¶
Package grpc provides generic functionality for grpc ¶
Package grpc provides generic functionality for grpc
Index ¶
- Constants
- Variables
- func BidirectionalStream[Q any, R any](ctx context.Context, stream ServerStream, concurrency int, ...) (err error)
- func BidirectionalStreamClient(stream ClientStream, dataProvider, newData func() any, f func(any, error)) (err error)
- func FromGRPCMethod(ctx context.Context) string
- func FromIncomingContext(ctx context.Context) (metadata.MD, bool)
- func NewOutgoingContext(ctx context.Context, md MD) context.Context
- func WithGRPCMethod(ctx context.Context, method string) context.Context
- func WrapGRPCMethod(ctx context.Context, method string) context.Context
- type CallOption
- type Client
- type ClientConn
- type ClientStream
- type Codec
- type DialOption
- type MD
- type Option
- func WithAddrs(addrs ...string) Option
- func WithAuthority(a string) Option
- func WithBackoff(bo backoff.Backoff) Option
- func WithBackoffBaseDelay(dur string) Option
- func WithBackoffJitter(j float64) Option
- func WithBackoffMaxDelay(dur string) Option
- func WithBackoffMultiplier(m float64) Option
- func WithCallContentSubtype(contentSubtype string) Option
- func WithCallOptions(opts ...grpc.CallOption) Option
- func WithCircuitBreaker(cb circuitbreaker.CircuitBreaker) Option
- func WithClientInterceptors(names ...string) Option
- func WithConnectionPoolRebalanceDuration(dur string) Option
- func WithConnectionPoolSize(size int) Option
- func WithDialOptions(opts ...grpc.DialOption) Option
- func WithDialer(der net.Dialer) Option
- func WithDisableRetry(disable bool) Option
- func WithEnableConnectionPoolRebalance(flg bool) Option
- func WithErrGroup(eg errgroup.Group) Option
- func WithHealthCheckDuration(dur string) Option
- func WithIdleTimeout(dur string) Option
- func WithInitialConnectionWindowSize(size int32) Option
- func WithInitialWindowSize(size int32) Option
- func WithInsecure(flg bool) Option
- func WithKeepaliveParams(t, to string, permitWithoutStream bool) Option
- func WithMaxCallAttempts(n int) Option
- func WithMaxHeaderListSize(size uint32) Option
- func WithMaxMsgSize(size int) Option
- func WithMaxRecvMsgSize(size int) Option
- func WithMaxRetryRPCBufferSize(size int) Option
- func WithMaxSendMsgSize(size int) Option
- func WithMinConnectTimeout(dur string) Option
- func WithOldConnCloseDuration(dur string) Option
- func WithReadBufferSize(size int) Option
- func WithResolveDNS(flg bool) Option
- func WithSharedWriteBuffer(enable bool) Option
- func WithTLSConfig(cfg *tls.Config) Option
- func WithUserAgent(ua string) Option
- func WithWaitForReady(flg bool) Option
- func WithWriteBufferSize(size int) Option
- type Server
- type ServerOption
- func ConnectionTimeout(d time.Duration) ServerOption
- func Creds(c credentials.TransportCredentials) ServerOption
- func HeaderTableSize(size uint32) ServerOption
- func InitialConnWindowSize(size int32) ServerOption
- func InitialWindowSize(size int32) ServerOption
- func KeepaliveEnforcementPolicy(kep keepalive.EnforcementPolicy) ServerOption
- func KeepaliveParams(kp keepalive.ServerParameters) ServerOption
- func MaxConcurrentStreams(n uint32) ServerOption
- func MaxHeaderListSize(size uint32) ServerOption
- func MaxRecvMsgSize(size int) ServerOption
- func MaxSendMsgSize(size int) ServerOption
- func NumStreamWorkers(n uint32) ServerOption
- func ReadBufferSize(size int) ServerOption
- func SharedWriteBuffer(val bool) ServerOption
- func WaitForHandlers(val bool) ServerOption
- func WriteBufferSize(size int) ServerOption
- type ServerStream
- type StreamClientInterceptor
- type StreamHandler
- type StreamServerInfo
- type StreamServerInterceptor
- type UnaryClientInterceptor
- type UnaryHandler
- type UnaryServerInfo
- type UnaryServerInterceptor
Constants ¶
const GRPCMethodContextKey contextKey = "grpc_method"
GRPCMethodContextKey represents a context key for gRPC method. This is exported only for testing.
const Name = "proto"
Name represents the codec name.
Variables ¶
var ( StatsHandler = grpc.StatsHandler WithStatsHandler = grpc.WithStatsHandler )
var ( UnaryInterceptor = grpc.UnaryInterceptor ChainUnaryInterceptor = grpc.ChainUnaryInterceptor StreamInterceptor = grpc.StreamInterceptor ChainStreamInterceptor = grpc.ChainStreamInterceptor )
var ErrServerStopped = grpc.ErrServerStopped
ErrServerStopped indicates that the operation is now illegal because of the server being stopped.
Functions ¶
func BidirectionalStream ¶
func BidirectionalStream[Q any, R any]( ctx context.Context, stream ServerStream, concurrency int, f func(context.Context, *Q) (*R, error), ) (err error)
BidirectionalStream represents gRPC bidirectional stream server handler. It receives messages from the stream, calls the function with the received message, and sends the returned message to the stream. It limits the number of concurrent calls to the function with the concurrency integer. It records errors and returns them as a single error.
func BidirectionalStreamClient ¶ added in v0.0.25
func BidirectionalStreamClient( stream ClientStream, dataProvider, newData func() any, f func(any, error), ) (err error)
BidirectionalStreamClient is gRPC client stream.
func FromGRPCMethod ¶ added in v1.5.4
FromGRPCMethod returns the value associated with this context for key (grpcMethodContextKey).
func FromIncomingContext ¶ added in v1.7.11
func NewOutgoingContext ¶ added in v1.7.11
func WithGRPCMethod ¶ added in v1.5.4
WithGRPCMethod returns a copy of parent in which the method associated with key (grpcMethodContextKey).
Types ¶
type CallOption ¶
type CallOption = grpc.CallOption
type Client ¶
type Client interface { StartConnectionMonitor(ctx context.Context) (<-chan error, error) Connect(ctx context.Context, addr string, dopts ...DialOption) (pool.Conn, error) IsConnected(ctx context.Context, addr string) bool Disconnect(ctx context.Context, addr string) error Range(ctx context.Context, f func(ctx context.Context, addr string, conn *ClientConn, copts ...CallOption) error) error RangeConcurrent(ctx context.Context, concurrency int, f func(ctx context.Context, addr string, conn *ClientConn, copts ...CallOption) error) error OrderedRange(ctx context.Context, order []string, f func(ctx context.Context, addr string, conn *ClientConn, copts ...CallOption) error) error OrderedRangeConcurrent(ctx context.Context, order []string, concurrency int, f func(ctx context.Context, addr string, conn *ClientConn, copts ...CallOption) error) error Do(ctx context.Context, addr string, f func(ctx context.Context, conn *ClientConn, copts ...CallOption) (any, error)) (any, error) RoundRobin(ctx context.Context, f func(ctx context.Context, conn *ClientConn, copts ...CallOption) (any, error)) (any, error) GetDialOption() []DialOption GetCallOption() []CallOption GetBackoff() backoff.Backoff SetDisableResolveDNSAddr(addr string, disabled bool) ConnectedAddrs() []string Close(ctx context.Context) error }
type ClientConn ¶
type ClientConn = pool.ClientConn
type ClientStream ¶ added in v0.0.27
type ClientStream = grpc.ClientStream
type Codec ¶ added in v1.4.0
type Codec struct{}
Codec represents a gRPC codec.
type DialOption ¶
type DialOption = pool.DialOption
type Option ¶
type Option func(*gRPCClient)
func WithAuthority ¶ added in v1.7.14
func WithBackoff ¶
func WithBackoffBaseDelay ¶ added in v1.0.0
func WithBackoffJitter ¶ added in v1.0.0
func WithBackoffMaxDelay ¶ added in v1.0.0
func WithBackoffMultiplier ¶ added in v1.0.0
func WithCallContentSubtype ¶ added in v1.7.14
func WithCallOptions ¶
func WithCallOptions(opts ...grpc.CallOption) Option
func WithCircuitBreaker ¶ added in v1.6.0
func WithCircuitBreaker(cb circuitbreaker.CircuitBreaker) Option
func WithClientInterceptors ¶ added in v1.6.0
func WithConnectionPoolRebalanceDuration ¶ added in v0.0.27
func WithConnectionPoolSize ¶ added in v0.0.27
func WithDialOptions ¶
func WithDialOptions(opts ...grpc.DialOption) Option
func WithDialer ¶
func WithDisableRetry ¶ added in v1.7.14
func WithEnableConnectionPoolRebalance ¶ added in v0.0.27
func WithErrGroup ¶
func WithHealthCheckDuration ¶
func WithIdleTimeout ¶ added in v1.7.14
func WithInitialWindowSize ¶
func WithInsecure ¶
func WithKeepaliveParams ¶
func WithMaxCallAttempts ¶ added in v1.7.14
func WithMaxHeaderListSize ¶ added in v1.7.14
func WithMaxMsgSize ¶
func WithMaxRecvMsgSize ¶
func WithMaxSendMsgSize ¶
func WithMinConnectTimeout ¶ added in v1.0.0
func WithOldConnCloseDuration ¶ added in v0.0.29
func WithReadBufferSize ¶
func WithResolveDNS ¶ added in v0.0.45
func WithSharedWriteBuffer ¶ added in v1.7.14
func WithTLSConfig ¶
func WithUserAgent ¶ added in v1.7.14
func WithWaitForReady ¶
func WithWriteBufferSize ¶
type Server ¶
Server represents a gRPC server to serve RPC requests.
func NewServer ¶ added in v1.0.0
func NewServer(opts ...ServerOption) *Server
NewServer returns the gRPC server.
type ServerOption ¶ added in v0.0.27
type ServerOption = grpc.ServerOption
ServerOption represents a gRPC server option.
func ConnectionTimeout ¶ added in v1.0.0
func ConnectionTimeout(d time.Duration) ServerOption
ConnectionTimeout is a alias of grpc.ConnectionTimeout that sets the timeout for connection establishment (up to and including HTTP/2 handshaking) for all new connections.
func Creds ¶ added in v1.0.0
func Creds(c credentials.TransportCredentials) ServerOption
Creds is a alias of grpc.Creds that sets credentials for server connections.
func HeaderTableSize ¶ added in v1.0.0
func HeaderTableSize(size uint32) ServerOption
HeaderTableSize is a alias of grpc.HeaderTableSize that sets the size of dynamic header table for stream.
func InitialConnWindowSize ¶ added in v1.0.0
func InitialConnWindowSize(size int32) ServerOption
InitialConnWindowSize is a alias of grpc.InitialConnWindowSize that sets window size for a connection.
func InitialWindowSize ¶ added in v1.0.0
func InitialWindowSize(size int32) ServerOption
InitialWindowSize is a alias of grpc.InitialWindowSize that sets window size for stream.
func KeepaliveEnforcementPolicy ¶ added in v1.3.1
func KeepaliveEnforcementPolicy(kep keepalive.EnforcementPolicy) ServerOption
KeepaliveEnforcementPolicy is a alias of grpc.KeepaliveEnforcementPolicy that sets keepalive enforcement policy for the server.
func KeepaliveParams ¶ added in v1.0.0
func KeepaliveParams(kp keepalive.ServerParameters) ServerOption
KeepaliveParams is a alias of grpc.KeepaliveParams that sets keepalive and max-age parameters for the server.
func MaxConcurrentStreams ¶ added in v1.7.14
func MaxConcurrentStreams(n uint32) ServerOption
MaxConcurrentStreams returns a ServerOption that will apply a limit on the number of concurrent streams to each ServerTransport.
func MaxHeaderListSize ¶ added in v1.0.0
func MaxHeaderListSize(size uint32) ServerOption
MaxHeaderListSize is a alias of grpc.MaxHeaderListSize that sets the max (uncompressed) size of header list that the server is prepared to accept.
func MaxRecvMsgSize ¶ added in v1.0.0
func MaxRecvMsgSize(size int) ServerOption
MaxRecvMsgSize is a alias of grpc.MaxRecvMsgSize to set the max message size in bytes the server can receive.
func MaxSendMsgSize ¶ added in v1.0.0
func MaxSendMsgSize(size int) ServerOption
MaxSendMsgSize is a alias of grpc.MaxSendMsgSize to set the max message size in bytes the server can send.
func NumStreamWorkers ¶ added in v1.7.14
func NumStreamWorkers(n uint32) ServerOption
NumStreamWorkers returns a ServerOption that sets the number of worker goroutines that should be used to process incoming streams. Setting this to zero (default) will disable workers and spawn a new goroutine for each stream.
func ReadBufferSize ¶ added in v1.0.0
func ReadBufferSize(size int) ServerOption
ReadBufferSize is a alias of grpc.ReadBufferSize that lets you set the size of read buffer.
func SharedWriteBuffer ¶ added in v1.7.14
func SharedWriteBuffer(val bool) ServerOption
SharedWriteBuffer allows reusing per-connection transport write buffer. If this option is set to true every connection will release the buffer after flushing the data on the wire.
func WaitForHandlers ¶ added in v1.7.14
func WaitForHandlers(val bool) ServerOption
WaitForHandlers cause Stop to wait until all outstanding method handlers have exited before returning. If false, Stop will return as soon as all connections have closed, but method handlers may still be running. By default, Stop does not wait for method handlers to return.
func WriteBufferSize ¶ added in v1.0.0
func WriteBufferSize(size int) ServerOption
WriteBufferSize is a alias of grpc.WriteBufferSize to determines how much data can be batched before doing a write on the wire.
type ServerStream ¶ added in v1.0.0
type ServerStream = grpc.ServerStream
type StreamClientInterceptor ¶ added in v1.6.0
type StreamClientInterceptor = grpc.StreamClientInterceptor
type StreamHandler ¶ added in v1.0.0
type StreamHandler = grpc.StreamHandler
type StreamServerInfo ¶ added in v1.0.0
type StreamServerInfo = grpc.StreamServerInfo
type StreamServerInterceptor ¶ added in v0.0.39
type StreamServerInterceptor = grpc.StreamServerInterceptor
type UnaryClientInterceptor ¶ added in v1.6.0
type UnaryClientInterceptor = grpc.UnaryClientInterceptor
type UnaryHandler ¶ added in v1.0.0
type UnaryHandler = grpc.UnaryHandler
type UnaryServerInfo ¶ added in v1.0.0
type UnaryServerInfo = grpc.UnaryServerInfo
type UnaryServerInterceptor ¶ added in v0.0.39
type UnaryServerInterceptor = grpc.UnaryServerInterceptor
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package admin provides grpc admin metrics registration API for providing grpc metrics endpoints
|
Package admin provides grpc admin metrics registration API for providing grpc metrics endpoints |
Package codes provides status codes of grpc
|
Package codes provides status codes of grpc |
Package credentials provides generic functionality for grpc credentials setting
|
Package credentials provides generic functionality for grpc credentials setting |
Package errdetails provides error detail for gRPC status
|
Package errdetails provides error detail for gRPC status |
Package health provides generic functionality for grpc health checks.
|
Package health provides generic functionality for grpc health checks. |
interceptor
|
|
client/metric
Package metric provides gRPC client interceptors for client metric
|
Package metric provides gRPC client interceptors for client metric |
server/logging
Package logging provides gRPC interceptors for access logging
|
Package logging provides gRPC interceptors for access logging |
server/recover
Package recover provides gRPC interceptors for recovery
|
Package recover provides gRPC interceptors for recovery |
Package keepalive provides grpc keepalive configuration
|
Package keepalive provides grpc keepalive configuration |
Package pool provides gRPC connection pool client
|
Package pool provides gRPC connection pool client |
Package proto provides proto file logic
|
Package proto provides proto file logic |
Package reflection provides grpc reflection for providing grpc server proto specs
|
Package reflection provides grpc reflection for providing grpc server proto specs |
Package status provides statuses and errors returned by grpc handler functions
|
Package status provides statuses and errors returned by grpc handler functions |
Package types provides alias of protobuf library types
|
Package types provides alias of protobuf library types |