mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-14 00:47:21 +00:00
52600a897a
ChunkReporter is more flexible and will allow code reuse for unit chunking. ChanReporter was added as a way to maintain the original channel functionality, so this PR should not alter existing behavior.
22 lines
545 B
Go
22 lines
545 B
Go
package sources
|
|
|
|
import (
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
|
|
)
|
|
|
|
var _ ChunkReporter = (*ChanReporter)(nil)
|
|
|
|
// ChanReporter is a ChunkReporter that writes to a channel.
|
|
type ChanReporter struct {
|
|
Ch chan<- *Chunk
|
|
}
|
|
|
|
func (c ChanReporter) ChunkOk(ctx context.Context, chunk Chunk) error {
|
|
return common.CancellableWrite(ctx, c.Ch, &chunk)
|
|
}
|
|
|
|
func (ChanReporter) ChunkErr(ctx context.Context, err error) error {
|
|
ctx.Logger().Error(err, "error chunking")
|
|
return nil
|
|
}
|