Documentation ¶
Overview ¶
Package context provides facilities for storing and retrieving values from context objects.
Index ¶
- Variables
- func AuthInfoFrom(ctx Context) (credentials.AuthInfo, bool)
- func AuthenticatedCallerFrom(ctx Context) (string, bool)
- func IsInNetwork(ctx Context, network Network) bool
- func LogInjectStreamServerInterceptor(logger Logger) grpc.StreamServerInterceptor
- func LogInjectUnaryServerInterceptor(logger Logger) grpc.UnaryServerInterceptor
- func MetadataFrom(ctx Context) (map[string][]string, bool)
- func PeerAddrFrom(ctx Context) (netip.Addr, bool)
- func PeerFrom(ctx Context) (*peer.Peer, bool)
- func WithCancel(ctx Context) (Context, CancelFunc)
- func WithDeadline(ctx Context, deadline time.Time) (Context, CancelFunc)
- func WithTimeout(ctx Context, timeout time.Duration) (Context, CancelFunc)
- type CancelFunc
- type Context
- type Logger
- type Network
Constants ¶
This section is empty.
Variables ¶
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 ¶
AuthenticatedCallerFrom returns the authenticated caller from the context.
func IsInNetwork ¶ added in v0.3.0
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 ¶
MetadataFrom is a convenience wrapper around retrieving the gRPC metadata from an incoming request.
func PeerAddrFrom ¶ added in v0.3.0
PeerAddrFrom is a convenience wrapper around retrieving the gRPC peer address from an incoming request.
func PeerFrom ¶ added in v0.3.0
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 ¶
Context is an alias to context.Context for convenience and to avoid confusion with the context package.
func WithAuthenticatedCaller ¶
WithAuthenticatedCaller returns a context with the authenticated caller set.
func WithLogger ¶
WithLogger returns a context with the given logger set.
type Logger ¶ added in v0.3.1
Logger is an alias to slog.Logger for convenience.
func LoggerFrom ¶
LoggerFrom returns the logger from the context. If no logger is set, the default logger is returned.