flexiwriter

package
v0.0.1-beta.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2024 License: BSD-3-Clause, BSD-3-Clause Imports: 2 Imported by: 0

README

FlexiWriter

An io.Writer which allows dynamic addition and removal of child writers, like a flexible io.MultiWriter.

Documentation

Overview

Package flexiwriter - Like io.MultiWriter, but with removable writers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer is like io.MultiWriter, but with dynamic addition and removal of writers. Writer's are safe to be called concurrently from multiple goroutines.

func New

func New(ws ...io.Writer) *Writer

New returns a new Writer, ready for use. Any writers passed to new will be added to the returned Writer as if pased to Add with a nil onremove.

func (*Writer) Add

func (fw *Writer) Add(w io.Writer, onremove func(err error))

Add adds a new writer to fw. On removal, onremove wil be called in a separate goroutine if not nil and passed any error which caused the removal. If onremove was called as a result of calling fw.Remove, onremove will be passed nil. If w has already been added to fw, w's existing onremove will set to the onremove passed to Add. Adding a nil io.Writer is a no-op.

func (*Writer) Remove

func (fw *Writer) Remove(w io.Writer) bool

Remove removes a writer from fw. If the writer was added with a non-nil onremove function, it will be called and passed nil. If w isn't in fw, as can happen if the writer is removed by fw.Write, Remove is a no-op. Remove returns true if w was in fw.

func (*Writer) Write

func (fw *Writer) Write(p []byte) (n int, err error)

Write satisfies io.Writer. If any of fw's writers returns an error, its onremove function is called and it is removed. The size of p and nil are returned. Write blocks until all of the underlying writes have finished.

func (*Writer) WriteString

func (fw *Writer) WriteString(s string)

WriteString is a convenience wrapper around fw.Write which writes s.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL