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 *slog.Logger) grpc.StreamServerInterceptor
- func LogInjectUnaryServerInterceptor(logger *slog.Logger) grpc.UnaryServerInterceptor
- func LoggerFrom(ctx Context) *slog.Logger
- 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 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 *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 ¶
LoggerFrom returns the logger from the context. If no logger is set, the default logger is returned.
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.