context

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package context provides facilities for storing and retrieving values from context objects.

Index

Constants

This section is empty.

Variables

View Source
var Canceled = context.Canceled

Canceled is an alias to context.Canceled for convenience and to avoid confusion with the context package.

Functions

func AuthInfoFrom

func AuthInfoFrom(ctx Context) (credentials.AuthInfo, bool)

AuthInfoFrom is a convenience wrapper around retrieving the gRPC authentication info from an incoming request.

func AuthenticatedCallerFrom

func AuthenticatedCallerFrom(ctx Context) (string, bool)

AuthenticatedCallerFrom returns the authenticated caller from the context.

func LogInjectStreamServerInterceptor

func LogInjectStreamServerInterceptor(logger *slog.Logger) grpc.StreamServerInterceptor

LogInjectStreamServerInterceptor returns a stream server interceptor that injects the logger into the context.

func LogInjectUnaryServerInterceptor

func LogInjectUnaryServerInterceptor(logger *slog.Logger) grpc.UnaryServerInterceptor

LogInjectUnaryServerInterceptor returns a unary server interceptor that injects the logger into the context.

func LoggerFrom

func LoggerFrom(ctx Context) *slog.Logger

LoggerFrom returns the logger from the context. If no logger is set, the default logger is returned.

func MetadataFrom

func MetadataFrom(ctx Context) (map[string][]string, bool)

MetadataFrom is a convenience wrapper around retrieving the gRPC metadata from an incoming request.

func WithCancel

func WithCancel(ctx Context) (Context, CancelFunc)

WithCancel returns a context with the given cancel function.

func WithDeadline

func WithDeadline(ctx Context, deadline time.Time) (Context, CancelFunc)

WithDeadline returns a context with the given deadline.

func WithTimeout

func WithTimeout(ctx Context, timeout time.Duration) (Context, CancelFunc)

WithTimeout returns a context with the given timeout.

Types

type CancelFunc

type CancelFunc = context.CancelFunc

CancelFunc is an alias to context.CancelFunc for convenience and to avoid confusion with the context package.

type Context

type Context = context.Context

Context is an alias to context.Context for convenience and to avoid confusion with the context package.

func Background

func Background() Context

Background returns a background context.

func WithAuthenticatedCaller

func WithAuthenticatedCaller(ctx Context, id string) Context

WithAuthenticatedCaller returns a context with the authenticated caller set.

func WithLogger

func WithLogger(ctx Context, logger *slog.Logger) Context

WithLogger returns a context with the given logger set.

Jump to

Keyboard shortcuts

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