skip

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

`skip` allow users to skip interceptors in certain condition.

Users can use grpc type, service name, method name and metadata to determine whether to skip the interceptor.

Example (Initialization)

Simple example of skipping auth interceptor in the reflection method.

package main

import (
	"context"

	"google.golang.org/grpc"

	"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors"
	"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/auth"
	"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/skip"
)

// Simple example of skipping auth interceptor in the reflection method.
func main() {
	_ = grpc.NewServer(
		grpc.UnaryInterceptor(skip.UnaryServerInterceptor(auth.UnaryServerInterceptor(dummyAuth), SkipReflectionService)),
		grpc.StreamInterceptor(skip.StreamServerInterceptor(auth.StreamServerInterceptor(dummyAuth), SkipReflectionService)),
	)
}

func dummyAuth(ctx context.Context) (context.Context, error) {
	return ctx, nil
}

func SkipReflectionService(_ context.Context, _ interceptors.GRPCType, service string, _ string) bool {
	return service != "grpc.reflection.v1alpha.ServerReflection"
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func StreamServerInterceptor

func StreamServerInterceptor(in grpc.StreamServerInterceptor, filter Filter) grpc.StreamServerInterceptor

StreamServerInterceptor returns a new streaming server interceptor that determines whether to skip the input interceptor.

func UnaryServerInterceptor

func UnaryServerInterceptor(in grpc.UnaryServerInterceptor, filter Filter) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a new unary server interceptor that determines whether to skip the input interceptor.

Types

type Filter

type Filter func(ctx context.Context, typ interceptors.GRPCType, svc string, method string) bool

Jump to

Keyboard shortcuts

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