grpc

package module
v0.0.0-...-0807185 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

This package provides Sentinel integration for gRPC.

For server/client side, users may create a gRPC server/client with Sentinel interceptor. A sample of server side:

import (
	sentinelPlugin "github.com/sentinel-group/sentinel-go-adapters/grpc"
	"google.golang.org/grpc"
)

// Create with Sentinel interceptor
s := grpc.NewServer(grpc.UnaryInterceptor(sentinelPlugin.NewUnaryServerInterceptor()))

The plugin extracts service FullMethod as the resource name by default. Users may provide customized resource name extractor when creating new Sentinel interceptors (via options).

Fallback logic: the plugin will return the BlockError by default if current request is blocked by Sentinel rules. Users may also provide customized fallback logic via WithXxxBlockFallback(handler) options.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStreamClientInterceptor

func NewStreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor

NewStreamClientInterceptor creates the stream client interceptor wrapped with Sentinel entry.

func NewStreamServerInterceptor

func NewStreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor

NewStreamServerInterceptor creates the unary stream interceptor wrapped with Sentinel entry.

func NewUnaryClientInterceptor

func NewUnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor

NewUnaryClientInterceptor creates the unary client interceptor wrapped with Sentinel entry.

func NewUnaryServerInterceptor

func NewUnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor

NewUnaryServerInterceptor creates the unary server interceptor wrapped with Sentinel entry.

Types

type Option

type Option func(*options)

func WithStreamClientBlockFallback

func WithStreamClientBlockFallback(fn func(context.Context, *grpc.StreamDesc, *grpc.ClientConn, string, *base.BlockError) (grpc.ClientStream, error)) Option

WithStreamClientBlockFallback sets the block fallback handler of stream client request.

func WithStreamClientResourceExtractor

func WithStreamClientResourceExtractor(fn func(context.Context, *grpc.StreamDesc, *grpc.ClientConn, string) string) Option

WithStreamClientResourceExtractor sets the resource extractor of stream client request.

func WithStreamServerBlockFallback

func WithStreamServerBlockFallback(fn func(interface{}, grpc.ServerStream, *grpc.StreamServerInfo, *base.BlockError) error) Option

WithStreamServerBlockFallback sets the block fallback handler of stream server request.

func WithStreamServerResourceExtractor

func WithStreamServerResourceExtractor(fn func(interface{}, grpc.ServerStream, *grpc.StreamServerInfo) string) Option

WithStreamServerResourceExtractor sets the resource extractor of stream server request.

func WithUnaryClientBlockFallback

func WithUnaryClientBlockFallback(fn func(context.Context, string, interface{}, *grpc.ClientConn, *base.BlockError) error) Option

WithUnaryClientBlockFallback sets the block fallback handler of unary client request. The second string parameter is the full method name of current invocation.

func WithUnaryClientResourceExtractor

func WithUnaryClientResourceExtractor(fn func(context.Context, string, interface{}, *grpc.ClientConn) string) Option

WithUnaryClientResourceExtractor sets the resource extractor of unary client request. The second string parameter is the full method name of current invocation.

func WithUnaryServerBlockFallback

func WithUnaryServerBlockFallback(fn func(context.Context, interface{}, *grpc.UnaryServerInfo, *base.BlockError) (interface{}, error)) Option

WithUnaryServerBlockFallback sets the block fallback handler of unary server request.

func WithUnaryServerResourceExtractor

func WithUnaryServerResourceExtractor(fn func(context.Context, interface{}, *grpc.UnaryServerInfo) string) Option

WithUnaryServerResourceExtractor sets the resource extractor of unary server request.

Jump to

Keyboard shortcuts

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