func wrapStreamWithAuth(authDesc StreamAuthDesc, desc *grpc.StreamDesc, handler interface{}) { h := desc.Handler desc.Handler = func(srv interface{}, stream grpc.ServerStream) error { stream = &authServerStream{stream, authDesc, handler} return h(srv, stream) } }
func wrapStreamWithErrorMapper(srv *grpc.ServiceDesc, desc grpc.StreamDesc, mapper ErrorMapper) grpc.StreamDesc { h := desc.Handler desc.Handler = func(srv interface{}, stream grpc.ServerStream) (err error) { err = h(srv, stream) if err != nil { if e := mapper.HandleError(err); e != nil { err = e } return err } return nil } return desc }
func wrapStreamWithTracer(srv *grpc.ServiceDesc, desc grpc.StreamDesc) grpc.StreamDesc { name := "/" + srv.ServiceName + "/" + desc.StreamName + "/root" h := desc.Handler desc.Handler = func(srv interface{}, stream grpc.ServerStream) (err error) { span, ctx := trace.New(stream.Context(), name, trace.WithPanicGuard) defer func(errPtr *error) { if span.Failed && *errPtr == nil { *errPtr = grpc.Errorf(codes.Internal, "internal server error") } }(&err) defer span.Close() stream = wrapServerSteamWithContext(stream, ctx) return h(srv, stream) } return desc }