interceptor

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RequestId            = "request_id"
	RequestIDHeader      = "x-request-id"
	DeviceIDHeader       = "x-device-id"
	PathHeader           = "x-request-path"
	MethodHeader         = "x-request-method"
	TraceidHeader        = "x-b3-traceid"
	SpanidHeader         = "x-b3-spanid"
	ParentspanidHeader   = "x-b3-parentspanid"
	SampledHeader        = "x-b3-sampled"
	FlagsHeader          = "x-b3-flags"
	SpanContextHeader    = "x-ot-span-context"
	ResponseStatusHeader = "x-response-status"

	HeaderMap = map[string]string{
		RequestIDHeader:    RequestId,
		DeviceIDHeader:     "device_id",
		TraceidHeader:      "traceid",
		SpanidHeader:       "spanid",
		SpanidHeader:       "spanid",
		ParentspanidHeader: "parentspanid",
		SampledHeader:      "sampled",
		FlagsHeader:        "flags",
		SpanContextHeader:  "span_context",
	}
)

常用的header key

Functions

func AuthStreamServerInterceptor added in v0.2.18

func AuthStreamServerInterceptor(authFunc Authorize) grpc.StreamServerInterceptor

AuthStreamServerInterceptor returns a new unary server interceptors that performs per-request auth.

func AuthUnaryServerInterceptor added in v0.2.18

func AuthUnaryServerInterceptor(authFunc Authorize) grpc.UnaryServerInterceptor

AuthUnaryServerInterceptor returns a new unary server interceptors that performs per-request auth.

func ChainContext

func ChainContext(ctx context.Context, md metadata.MD) context.Context

ChainContext

func TracerClientStreamInterceptor

func TracerClientStreamInterceptor(tracer opentracing.Tracer) grpc.StreamClientInterceptor

TracerClientStreamInterceptor

func TracerServerStreamInterceptor

func TracerServerStreamInterceptor(tracer opentracing.Tracer) grpc.StreamServerInterceptor

TracerServerStreamInterceptor

func TracerServerUnaryInterceptor

func TracerServerUnaryInterceptor(tracer opentracing.Tracer) grpc.UnaryServerInterceptor

TracerServerUnaryInterceptor

func TracerUnaryClientInterceptor

func TracerUnaryClientInterceptor(tracer opentracing.Tracer) grpc.UnaryClientInterceptor

TracerClientInterceptor https://godoc.org/google.golang.org/grpc#UnaryClientInterceptor

Types

type Authorize added in v0.2.18

type Authorize func(context.Context, interface{}) (context.Context, error)

Authorize is the pluggable function that performs authentication.

The passed in `Context` will contain the gRPC metadata.MD object (for header-based authentication) and the peer.Peer information that can contain transport-based credentials (e.g. `credentials.AuthInfo`).

The returned context will be propagated to handlers, allowing user changes to `Context`. However, please make sure that the `Context` returned is a child `Context` of the one passed in.

If error is returned, its `grpc.Code()` will be returned to the user as well as the verbatim message. Please make sure you use `codes.Unauthenticated` (lacking auth) and `codes.PermissionDenied` (authed, but lacking perms) appropriately.

type MDCarrier

type MDCarrier struct {
	metadata.MD
}

MDCarrier custome carrier

func (MDCarrier) ForeachKey

func (m MDCarrier) ForeachKey(handler func(key, val string) error) error

ForeachKey conforms to the TextMapReader interface. TextMapReader is the Extract() carrier for the TextMap builtin format. With it, the caller can decode a propagated SpanContext as entries in a map of unicode strings.

type TextMapReader interface {
	// ForeachKey returns TextMap contents via repeated calls to the `handler`
	// function. If any call to `handler` returns a non-nil error, ForeachKey
	// terminates and returns that error.
	//
	// NOTE: The backing store for the TextMapReader may contain data unrelated
	// to SpanContext. As such, Inject() and Extract() implementations that
	// call the TextMapWriter and TextMapReader interfaces must agree on a
	// prefix or other convention to distinguish their own key:value pairs.
	//
	// The "foreach" callback pattern reduces unnecessary copying in some cases
	// and also allows implementations to hold locks while the map is read.
	ForeachKey(handler func(key, val string) error) error
}

func (MDCarrier) Set

func (m MDCarrier) Set(key, val string)

Set implements Set() of opentracing.TextMapWriter TextMapWriter is the Inject() carrier for the TextMap builtin format. With it, the caller can encode a SpanContext for propagation as entries in a map of unicode strings.

type TextMapWriter interface {
	// Set a key:value pair to the carrier. Multiple calls to Set() for the
	// same key leads to undefined behavior.
	//
	// NOTE: The backing store for the TextMapWriter may contain data unrelated
	// to SpanContext. As such, Inject() and Extract() implementations that
	// call the TextMapWriter and TextMapReader interfaces must agree on a
	// prefix or other convention to distinguish their own key:value pairs.
	Set(key, val string)
}

Directories

Path Synopsis
Package routerlimit provide router limit tools
Package routerlimit provide router limit tools
Package logging implements grpc logging middleware.
Package logging implements grpc logging middleware.

Jump to

Keyboard shortcuts

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