Files

1.2 KiB

streamctx

import "github.com/effective-security/porto/pkg/streamctx"

Package streamctx wraps a grpc.ServerStream so that its Context returns a replacement context. Stream interceptors use it to attach values (identity, correlation ID) to the context seen by the handler:

func interceptor(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
	ctx := context.WithValue(ss.Context(), key, value)
	return handler(srv, streamctx.WithContext(ctx, ss))
}

Index

func WithContext

func WithContext(ctx context.Context, ss grpc.ServerStream) grpc.ServerStream

WithContext returns a grpc.ServerStream whose Context method returns ctx. If ss was already produced by WithContext, its context is replaced in place and the same stream is returned (so earlier holders of that stream observe the new context); otherwise ss is wrapped.

Generated by gomarkdoc