middleware

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

README

Middleware

The core/middleware package is used to interact with HTTP & gRPC middlewares.

Middlewares

Examples

Chain gRPC middlewares
server = grpcsrv.New(nil, middleware.WithUnaryServerChain(
    metricsmw.UnaryServerInterceptor,
    tracingmw.UnaryServerInterceptor,
    paginationmw.UnaryServerInterceptor,
))

Documentation

Overview

Package middleware is used to interact with HTTP & gRPC middlewares.

Example
package main

import (
	"github.com/LUSHDigital/core/middleware"
	"github.com/LUSHDigital/core/middleware/metricsmw"
	"github.com/LUSHDigital/core/middleware/paginationmw"
	"github.com/LUSHDigital/core/middleware/tracingmw"
	"github.com/LUSHDigital/core/workers/grpcsrv"
)

var (
	server *grpcsrv.Server
)

func main() {
	server = grpcsrv.New(nil, middleware.WithUnaryServerChain(
		metricsmw.UnaryServerInterceptor,
		tracingmw.UnaryServerInterceptor,
		paginationmw.UnaryServerInterceptor,
	))
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChainStreamClient

func ChainStreamClient(interceptors ...grpc.StreamClientInterceptor) grpc.StreamClientInterceptor

ChainStreamClient creates a single interceptor out of a chain of many interceptors.

Execution is done in left-to-right order, including passing of context. For example ChainStreamClient(one, two, three) will execute one before two before three.

func ChainStreamServer

func ChainStreamServer(interceptors ...grpc.StreamServerInterceptor) grpc.StreamServerInterceptor

ChainStreamServer creates a single interceptor out of a chain of many interceptors.

Execution is done in left-to-right order, including passing of context. For example ChainUnaryServer(one, two, three) will execute one before two before three. If you want to pass context between interceptors, use WrapServerStream.

func ChainUnaryClient

func ChainUnaryClient(interceptors ...grpc.UnaryClientInterceptor) grpc.UnaryClientInterceptor

ChainUnaryClient creates a single interceptor out of a chain of many interceptors.

Execution is done in left-to-right order, including passing of context. For example ChainUnaryClient(one, two, three) will execute one before two before three.

func ChainUnaryServer

func ChainUnaryServer(interceptors ...grpc.UnaryServerInterceptor) grpc.UnaryServerInterceptor

ChainUnaryServer creates a single interceptor out of a chain of many interceptors.

Execution is done in left-to-right order, including passing of context. For example ChainUnaryServer(one, two, three) will execute one before two before three, and three will see context changes of one and two.

func WithStreamServerChain

func WithStreamServerChain(interceptors ...grpc.StreamServerInterceptor) grpc.ServerOption

WithStreamServerChain is a grpc.Server config option that accepts multiple stream interceptors. Basically syntactic sugar.

func WithUnaryServerChain

func WithUnaryServerChain(interceptors ...grpc.UnaryServerInterceptor) grpc.ServerOption

WithUnaryServerChain is a grpc.Server config option that accepts multiple unary interceptors. Basically syntactic sugar.

Types

type WrappedServerStream

type WrappedServerStream struct {
	grpc.ServerStream
	// WrappedContext is the wrapper's own Context. You can assign it.
	WrappedContext context.Context
}

WrappedServerStream is a thin wrapper around grpc.ServerStream that allows modifying context.

func WrapServerStream

func WrapServerStream(stream grpc.ServerStream) *WrappedServerStream

WrapServerStream returns a ServerStream that has the ability to overwrite context.

func (*WrappedServerStream) Context

func (w *WrappedServerStream) Context() context.Context

Context returns the wrapper's WrappedContext, overwriting the nested grpc.ServerStream.Context()

Directories

Path Synopsis
Package i18nmw provides transport middlewares for dealing with internationalisation.
Package i18nmw provides transport middlewares for dealing with internationalisation.
internal
Package metricsmw is used to record and expose metrics for an application.
Package metricsmw is used to record and expose metrics for an application.
Package paginationmw provides transport middlewares for dealing with pagination.
Package paginationmw provides transport middlewares for dealing with pagination.
Package tracingmw allows setting and tracing a request by injecting an id as part of it's headers, when dealing with HTTP, or it's context, when dealing with GRPC.
Package tracingmw allows setting and tracing a request by injecting an id as part of it's headers, when dealing with HTTP, or it's context, when dealing with GRPC.

Jump to

Keyboard shortcuts

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