context

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: Apache-2.0 Imports: 8 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 IsInNetwork added in v0.3.0

func IsInNetwork(ctx Context, network Network) bool

IsInNetwork returns true if the given context is from a peer in the given network.

func LogInjectStreamServerInterceptor

func LogInjectStreamServerInterceptor(logger Logger) grpc.StreamServerInterceptor

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

func LogInjectUnaryServerInterceptor

func LogInjectUnaryServerInterceptor(logger Logger) grpc.UnaryServerInterceptor

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

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 PeerAddrFrom added in v0.3.0

func PeerAddrFrom(ctx Context) (netip.Addr, bool)

PeerAddrFrom is a convenience wrapper around retrieving the gRPC peer address from an incoming request.

func PeerFrom added in v0.3.0

func PeerFrom(ctx Context) (*peer.Peer, bool)

PeerFrom is a convenience wrapper around retrieving the gRPC peer info 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 Logger) Context

WithLogger returns a context with the given logger set.

type Logger added in v0.3.1

type Logger = *slog.Logger

Logger is an alias to slog.Logger for convenience.

func LoggerFrom

func LoggerFrom(ctx Context) Logger

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

type Network added in v0.3.0

type Network interface {
	NetworkV4() netip.Prefix
	NetworkV6() netip.Prefix
}

Network is an interface that returns the IPv4 and IPv6 networks of the mesh.

Jump to

Keyboard shortcuts

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