| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package sender |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
|
| 9 |
"go.opentelemetry.io/collector/component" |
| 10 |
) |
| 11 |
|
| 12 |
type Sender[T any] interface { |
| 13 |
component.Component |
| 14 |
Send(context.Context, T) error |
| 15 |
} |
| 16 |
|
| 17 |
type SendFunc[T any] func(ctx context.Context, data T) error |
| 18 |
|
| 19 |
func NewSender[T any](consFunc SendFunc[T]) Sender[T] { |
| 20 |
return &sender[T]{consFunc: consFunc} |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
type sender[T any] struct { |
| 25 |
component.StartFunc |
| 26 |
component.ShutdownFunc |
| 27 |
consFunc SendFunc[T] |
| 28 |
} |
| 29 |
|
| 30 |
func (es *sender[T]) Send(ctx context.Context, req T) error { |
| 31 |
return es.consFunc(ctx, req) |
| 32 |
} |