Documentation ¶
Index ¶
- Constants
- type Writer
- type WriterOption
- func WithBufferedByteLimit(n int) WriterOption
- func WithBundleByteLimit(n int) WriterOption
- func WithBundleByteThreshold(n int) WriterOption
- func WithBundleCountThreshold(n int) WriterOption
- func WithDelayThreshold(delay time.Duration) WriterOption
- func WithErrorChannelCapacity(n int) WriterOption
- func WithOnError(f func(err error)) WriterOption
Constants ¶
const (
DefaultErrChanCapacity = 10
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is a io.Writer wrapper that uses a bundler to make Write lock-free, non-blocking and thread safe.
func NewWriter ¶
func NewWriter(w io.Writer, opts []WriterOption) *Writer
NewWriter creates a writer wrapping w with a bundler in order to never block the producers and drop writes if the underlying writer can't keep up with the flow of data.
Use a bundler.Writer when
onError := WithOnError(func(err error) { log.Printf("Dropped writes due to: %v", err) }) wr := NewWriter(w, []WriterOption{onError}) wr.Write([]byte("Hello, World!"))
See https://pkg.go.dev/google.golang.org/api/support/bundler for more info on bundler.
type WriterOption ¶
WriterOption can be used to setup the writer.
func WithBufferedByteLimit ¶
func WithBufferedByteLimit(n int) WriterOption
WithBufferedByteLimit sets the maximum number of bytes that the Bundler will keep in memory before returning ErrOverflow. The default is DefaultBufferedByteLimit.
func WithBundleByteLimit ¶
func WithBundleByteLimit(n int) WriterOption
WithBundleByteLimit sets the maximum size of a bundle, in bytes. Zero means unlimited. The default is DefaultBundleByteLimit.
func WithBundleByteThreshold ¶
func WithBundleByteThreshold(n int) WriterOption
WithBundleByteThreshold sets the max size of the bundle (in bytes) at which the bundler is flushed. The default is DefaultBundleByteThreshold.
func WithBundleCountThreshold ¶
func WithBundleCountThreshold(n int) WriterOption
WithBundleCountThreshold sets the max number of items after which the bundler is flushed. The default is DefaultBundleCountThreshold.
func WithDelayThreshold ¶
func WithDelayThreshold(delay time.Duration) WriterOption
WithDelayThreshold sets the interval at which the bundler is flushed. The default is DefaultDelayThreshold.
func WithErrorChannelCapacity ¶
func WithErrorChannelCapacity(n int) WriterOption
WithErrorChannelCapacity sets the buffer capacity of errors channel. The default is DefaultErrChanCapacity.
func WithOnError ¶
func WithOnError(f func(err error)) WriterOption
WithOnError sets the function to be executed on errors. The default is a simple log.