grpc

package
v1.7.12 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

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

View Source
const GRPCMethodContextKey contextKey = "grpc_method"

GRPCMethodContextKey represents a context key for gRPC method. This is exported only for testing.

View Source
const Name = "proto"

Name represents the codec name.

Variables

View Source
var (
	StatsHandler     = grpc.StatsHandler
	WithStatsHandler = grpc.WithStatsHandler
)
View Source
var (
	UnaryInterceptor       = grpc.UnaryInterceptor
	ChainUnaryInterceptor  = grpc.ChainUnaryInterceptor
	StreamInterceptor      = grpc.StreamInterceptor
	ChainStreamInterceptor = grpc.ChainStreamInterceptor
)
View Source
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() interface{},
	f func(interface{}, error),
) (err error)

BidirectionalStreamClient is gRPC client stream.

func FromGRPCMethod added in v1.5.4

func FromGRPCMethod(ctx context.Context) string

FromGRPCMethod returns the value associated with this context for key (grpcMethodContextKey).

func FromIncomingContext added in v1.7.11

func FromIncomingContext(ctx context.Context) (metadata.MD, bool)

func NewOutgoingContext added in v1.7.11

func NewOutgoingContext(ctx context.Context, md MD) context.Context

func WithGRPCMethod added in v1.5.4

func WithGRPCMethod(ctx context.Context, method string) context.Context

WithGRPCMethod returns a copy of parent in which the method associated with key (grpcMethodContextKey).

func WrapGRPCMethod added in v1.7.2

func WrapGRPCMethod(ctx context.Context, method string) context.Context

WrapGRPCMethod 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) (interface{}, error)) (interface{}, error)
	RoundRobin(ctx context.Context, f func(ctx context.Context,
		conn *ClientConn,
		copts ...CallOption) (interface{}, error)) (interface{}, error)
	GetDialOption() []DialOption
	GetCallOption() []CallOption
	GetBackoff() backoff.Backoff
	ConnectedAddrs() []string
	Close(ctx context.Context) error
}

func New

func New(opts ...Option) (c Client)

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.

func (Codec) Marshal added in v1.4.0

func (Codec) Marshal(obj interface{}) (data []byte, err error)

Marshal returns byte slice representing the proto message marshalling result.

func (Codec) Name added in v1.4.0

func (Codec) Name() string

func (Codec) Unmarshal added in v1.4.0

func (Codec) Unmarshal(data []byte, obj interface{}) (err error)

Unmarshal parses the byte stream data into v.

type DialOption

type DialOption = pool.DialOption

type MD added in v1.7.11

type MD = metadata.MD

type Option

type Option func(*gRPCClient)

func WithAddrs

func WithAddrs(addrs ...string) Option

func WithBackoff

func WithBackoff(bo backoff.Backoff) Option

func WithBackoffBaseDelay added in v1.0.0

func WithBackoffBaseDelay(dur string) Option

func WithBackoffJitter added in v1.0.0

func WithBackoffJitter(j float64) Option

func WithBackoffMaxDelay added in v1.0.0

func WithBackoffMaxDelay(dur string) Option

func WithBackoffMultiplier added in v1.0.0

func WithBackoffMultiplier(m float64) Option

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 WithClientInterceptors(names ...string) Option

func WithConnectionPoolRebalanceDuration added in v0.0.27

func WithConnectionPoolRebalanceDuration(dur string) Option

func WithConnectionPoolSize added in v0.0.27

func WithConnectionPoolSize(size int) Option

func WithDialOptions

func WithDialOptions(opts ...grpc.DialOption) Option

func WithDialer

func WithDialer(der net.Dialer) Option

func WithEnableConnectionPoolRebalance added in v0.0.27

func WithEnableConnectionPoolRebalance(flg bool) Option

func WithErrGroup

func WithErrGroup(eg errgroup.Group) Option

func WithHealthCheckDuration

func WithHealthCheckDuration(dur string) Option

func WithInitialConnectionWindowSize

func WithInitialConnectionWindowSize(size int) Option

func WithInitialWindowSize

func WithInitialWindowSize(size int) Option

func WithInsecure

func WithInsecure(flg bool) Option

func WithKeepaliveParams

func WithKeepaliveParams(t, to string, permitWithoutStream bool) Option

func WithMaxMsgSize

func WithMaxMsgSize(size int) Option

func WithMaxRecvMsgSize

func WithMaxRecvMsgSize(size int) Option

func WithMaxRetryRPCBufferSize

func WithMaxRetryRPCBufferSize(size int) Option

func WithMaxSendMsgSize

func WithMaxSendMsgSize(size int) Option

func WithMinConnectTimeout added in v1.0.0

func WithMinConnectTimeout(dur string) Option

func WithOldConnCloseDuration added in v0.0.29

func WithOldConnCloseDuration(dur string) Option

func WithReadBufferSize

func WithReadBufferSize(size int) Option

func WithResolveDNS added in v0.0.45

func WithResolveDNS(flg bool) Option

func WithTLSConfig

func WithTLSConfig(cfg *tls.Config) Option

func WithWaitForReady

func WithWaitForReady(flg bool) Option

func WithWriteBufferSize

func WithWriteBufferSize(size int) Option

type Server

type Server = grpc.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

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 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 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 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

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
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

Jump to

Keyboard shortcuts

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