Documentation ¶
Index ¶
- func Copy(src Source, dest Dest) error
- func NopWriteCloser(w io.Writer) io.WriteCloser
- type Dest
- func ToBuffer(closeCallback func(*bytes.Buffer) error) Dest
- func ToDiscard() Dest
- func ToError(err error) Dest
- func ToFile(path ...string) Dest
- func ToModeFile(mode os.FileMode, path ...string) Dest
- func ToWriteCloser(w io.WriteCloser) Dest
- func ToWriter(writer io.Writer) Dest
- func ToYaml(v interface{}) Dest
- type MultiCloser
- type Source
- func FromBytes(b []byte) Source
- func FromError(err error) Source
- func FromFile(path ...string) Source
- func FromReadCloser(rc io.ReadCloser) Source
- func FromReadCloserError(rc io.ReadCloser, err error) Source
- func FromReader(rc io.Reader) Source
- func FromString(s string) Source
- func FromYaml(v interface{}) Source
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NopWriteCloser ¶
func NopWriteCloser(w io.Writer) io.WriteCloser
NopWriteCloser works like io.NopCloser, but for writers.
Types ¶
type Dest ¶
type Dest func() (io.WriteCloser, error)
func ToBuffer ¶
ToBuffer buffers the contents of the stream and on Close() calls the callback returning its error.
func ToFile ¶
ToFile concatenates the given path segments with filepath.Join, creates any parent directoreis if needed, and writes the file.
func ToModeFile ¶
ToModeFile is like ToFile, but sets the permissions on the created file.
func ToWriteCloser ¶
func ToWriteCloser(w io.WriteCloser) Dest
ToWriteCloser forwards data to the given WriteCloser which will be closed after the copy finishes.
type MultiCloser ¶
type MultiCloser struct {
// contains filtered or unexported fields
}
MultiCloser calls Close() once on every added closer and returns a multierror of all errors encountered.
Example ¶
var mc MultiCloser mc.Add(ioutil.NopCloser(nil)) fmt.Println("closed:", mc.Close())
Output: closed: <nil>
func (*MultiCloser) Add ¶
func (mc *MultiCloser) Add(c io.Closer)
Add appends the closer to the internal list of closers.
func (*MultiCloser) Close ¶
func (mc *MultiCloser) Close() error
Close calls close on all closers, discarding them from the list. Modifying MultiCloser in your Close method will create a deadlock. At the end of this function, the close list will be empty and any encountered errors will be returned.
type Source ¶
type Source func() (io.ReadCloser, error)
func FromReadCloser ¶
func FromReadCloser(rc io.ReadCloser) Source
FromReadCloser reads the contents of the readcloser and takes ownership of closing it.
func FromReadCloserError ¶
func FromReadCloserError(rc io.ReadCloser, err error) Source
FromReadCloserError reads the contents of the readcloser and takes ownership of closing it. If err is non-nil, it is returned as a source.