func (a *vAdapter) sendEvents(ctx context.Context, baseEvents []types.BaseEvent) (int, error) {
	var success int

	for _, be := range baseEvents {
		ev := cloudevents.NewEvent(cloudevents.VersionV1)
		ev.SetSource(a.Source)

		details := getEventDetails(be)

		// CE envelop
		ev.SetID(fmt.Sprintf("%d", be.GetEvent().Key))
		ev.SetType(fmt.Sprintf(eventTypeFormat, details.Type))
		ev.SetTime(be.GetEvent().CreatedTime)
		ev.SetExtension(ceVSphereEventClass, details.Class)
		ev.SetExtension(ceVSphereAPIKey, a.VAPIVersion)

		if err := ev.SetData(a.PayloadEncoding, be); err != nil {
			return success, fmt.Errorf("set data on event: %w", err)
		}

		// TODO: better partial batch failure handling here?
		result := a.CEClient.Send(ctx, ev)
		if !cloudevents.IsACK(result) {
			logging.FromContext(ctx).Errorw("failed to send cloudevent", zap.Error(result))
			return success, result
		}
		success++
	}

	return success, nil
}
// sendEvents converts all events to cloud events and sends them to the
// configured sink. It returns the number of successfully processed events,
// which might 0, partial or all events. sendEvents returns when all events are
// processed or on the first error.
sendEvents converts all events to cloud events and sends them to the
configured sink. It returns the number of successfully processed events,
which might 0, partial or all events. sendEvents returns when all events are
processed or on the first error.
// sendEvents converts all events to cloud events and sends them to the // configured sink . It returns the number of successfully processed events // which might 0 partial or all events . sendEvents returns when all events are // processed or on the first error .
func (a *vAdapter) sendEvents(ctx context.Context, baseEvents []types.BaseEvent) (int, error) {
	var success int
	for _, be := range baseEvents {
		ev := cloudevents.NewEvent(cloudevents.VersionV1)
		ev.SetSource(a.Source)
		details := getEventDetails(be)
		ev.SetID(fmt.Sprintf("%d", be.GetEvent().Key))
		ev.SetType(fmt.Sprintf(eventTypeFormat, details.Type))
		ev.SetTime(be.GetEvent().CreatedTime)
		ev.SetExtension(ceVSphereEventClass, details.Class)
		ev.SetExtension(ceVSphereAPIKey, a.VAPIVersion)
		if err := ev.SetData(a.PayloadEncoding, be); err != nil {
			return success, fmt.Errorf("set data on event: %w", err)
		}
		result := a.CEClient.Send(ctx, ev)
		if !cloudevents.IsACK(result) {
			logging.FromContext(ctx).Errorw("failed to send cloudevent", zap.Error(result))
			return success, result
		}
		success++
	}
	return success, nil
}
func ( a * vAdapter ) sendEvents ( ctx context . Context , baseEvents [ ] types . BaseEvent ) ( int , error ) { var success int for _ , be := range baseEvents { ev := cloudevents . NewEvent ( cloudevents . VersionV1 ) ev . SetSource ( a . Source ) details := getEventDetails ( be ) ev . SetID ( fmt . Sprintf ( " " , be . GetEvent ( ) . Key ) ) ev . SetType ( fmt . Sprintf ( eventTypeFormat , details . Type ) ) ev . SetTime ( be . GetEvent ( ) . CreatedTime ) ev . SetExtension ( ceVSphereEventClass , details . Class ) ev . SetExtension ( ceVSphereAPIKey , a . VAPIVersion ) if err := ev . SetData ( a . PayloadEncoding , be ) ; err != nil { return success , fmt . Errorf ( " " , err ) } result := a . CEClient . Send ( ctx , ev ) if ! cloudevents . IsACK ( result ) { logging . FromContext ( ctx ) . Errorw ( " " , zap . Error ( result ) ) return success , result } success ++ } return success , nil }
sendEvents converts all events to cloud events and sends them to the
configured sink.
sendEvents converts all events to cloud events and sends them to the configured sink .
// CE envelop // TODO: better partial batch failure handling here?