rpcutil

package
v0.0.0-...-0332357 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAvailable

func CheckAvailable(fc FeatureChecker) grpc.UnaryServerInterceptor

CheckAvailable is a gRPC middleware that checks whether a method is ready to serve.

func ForwardToLeader

func ForwardToLeader[T any](fc ForwardChecker[T]) grpc.UnaryServerInterceptor

ForwardToLeader is a gRPC middleware that forwards the request to the leader if the current node is not the leader.

func FromGRPCError

func FromGRPCError(errIn error) error

FromGRPCError converts a gRPC error to a normalized error.

func Logger

func Logger(allowList []string, limiter *rate.Limiter) grpc.UnaryServerInterceptor

Logger is a gRPC middleware that logs the request and response. allowList is a list of methods that will be logged. limiter is used to limit the log rate.

func NormalizeError

func NormalizeError() grpc.UnaryServerInterceptor

NormalizeError is a gRPC middleware that normalizes the error.

func ToGRPCError

func ToGRPCError(errIn error) error

ToGRPCError converts an error to a gRPC error.

Types

type FeatureChecker

type FeatureChecker interface {
	Available(method string) bool
}

FeatureChecker defines an interface that checks whether a feature is available or under degradation.

type ForwardChecker

type ForwardChecker[T any] interface {
	// LeaderOnly returns whether the request is only allowed to handle by the leader.
	LeaderOnly(method string) bool
	// IsLeader returns whether the current node is the leader.
	IsLeader() bool
	// LeaderClient returns the leader client. If there is no leader, it should return
	// nil and errors.ErrMasterNoLeader.
	LeaderClient() (T, error)
}

ForwardChecker is used for checking whether a request should be forwarded or not.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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