Documentation
¶
Overview ¶
Package writer provides a common interface for writing data to one or more sources.
Index ¶
- Constants
- func DefaultLogger() *log.Logger
- func GetIOWriterFromContext(ctx context.Context) (io.Writer, error)
- func RegisterWriter(ctx context.Context, scheme string, init_func WriterInitializationFunc) error
- func Schemes() []string
- func SetIOWriterWithContext(ctx context.Context, wr io.Writer) (context.Context, error)
- type CwdWriter
- func (wr *CwdWriter) Close(ctx context.Context) error
- func (wr *CwdWriter) Flush(ctx context.Context) error
- func (wr *CwdWriter) SetLogger(ctx context.Context, logger *log.Logger) error
- func (wr *CwdWriter) Write(ctx context.Context, path string, fh io.ReadSeeker) (int64, error)
- func (wr *CwdWriter) WriterURI(ctx context.Context, path string) string
- type FileWriter
- func (wr *FileWriter) Close(ctx context.Context) error
- func (wr *FileWriter) Flush(ctx context.Context) error
- func (wr *FileWriter) SetLogger(ctx context.Context, logger *log.Logger) error
- func (wr *FileWriter) Write(ctx context.Context, path string, fh io.ReadSeeker) (int64, error)
- func (wr *FileWriter) WriterURI(ctx context.Context, path string) string
- type IOWriter
- func (io_wr *IOWriter) Close(ctx context.Context) error
- func (io_wr *IOWriter) Flush(ctx context.Context) error
- func (io_wr *IOWriter) SetLogger(ctx context.Context, logger *log.Logger) error
- func (io_wr *IOWriter) Write(ctx context.Context, path string, fh io.ReadSeeker) (int64, error)
- func (io_wr *IOWriter) WriterURI(ctx context.Context, path string) string
- type MultiWriter
- func (mw *MultiWriter) Close(ctx context.Context) error
- func (mw *MultiWriter) Flush(ctx context.Context) error
- func (mw *MultiWriter) SetLogger(ctx context.Context, logger *log.Logger) error
- func (mw *MultiWriter) Write(ctx context.Context, key string, fh io.ReadSeeker) (int64, error)
- func (mw *MultiWriter) WriterURI(ctx context.Context, key string) string
- type MultiWriterOptions
- type NullWriter
- func (wr *NullWriter) Close(ctx context.Context) error
- func (wr *NullWriter) Flush(ctx context.Context) error
- func (wr *NullWriter) SetLogger(ctx context.Context, logger *log.Logger) error
- func (wr *NullWriter) Write(ctx context.Context, path string, fh io.ReadSeeker) (int64, error)
- func (wr *NullWriter) WriterURI(ctx context.Context, path string) string
- type StdoutWriter
- func (wr *StdoutWriter) Close(ctx context.Context) error
- func (wr *StdoutWriter) Flush(ctx context.Context) error
- func (wr *StdoutWriter) SetLogger(ctx context.Context, logger *log.Logger) error
- func (wr *StdoutWriter) Write(ctx context.Context, path string, fh io.ReadSeeker) (int64, error)
- func (wr *StdoutWriter) WriterURI(ctx context.Context, path string) string
- type Writer
- func NewAsyncMultiWriter(ctx context.Context, writers ...Writer) (Writer, error)
- func NewCwdWriter(ctx context.Context, uri string) (Writer, error)
- func NewFileWriter(ctx context.Context, uri string) (Writer, error)
- func NewIOWriter(ctx context.Context, uri string) (Writer, error)
- func NewIOWriterWithWriter(ctx context.Context, wr io.Writer) (Writer, error)
- func NewMultiWriter(ctx context.Context, writers ...Writer) (Writer, error)
- func NewMultiWriterWithOptions(ctx context.Context, opts *MultiWriterOptions) (Writer, error)
- func NewNullWriter(ctx context.Context, uri string) (Writer, error)
- func NewRepoWriter(ctx context.Context, uri string) (Writer, error)
- func NewStdoutWriter(ctx context.Context, uri string) (Writer, error)
- func NewWriter(ctx context.Context, uri string) (Writer, error)
- type WriterInitializationFunc
Constants ¶
const IOWRITER_TARGET_KEY string = "github.com/whosonfirst/go-writer#io_writer"
IOWRITER_TARGET_KEY is the key used to store an `io.Writer` instance in a `context.Context` instance.
Variables ¶
This section is empty.
Functions ¶
func DefaultLogger ¶
DefaultLogger() returns a `log.Logger` instance that writes to `io.Discard`.
func GetIOWriterFromContext ¶
GetIOWriterFromContext returns the `io.Writer` instance associated with the `IOWRITER_TARGET_KEY` value in 'ctx'.
func RegisterWriter ¶
func RegisterWriter(ctx context.Context, scheme string, init_func WriterInitializationFunc) error
RegisterWriter registers 'scheme' as a key pointing to 'init_func' in an internal lookup table used to create new `Writer` instances by the `NewWriter` method.
Types ¶
type CwdWriter ¶
type CwdWriter struct { Writer // contains filtered or unexported fields }
CwdWriter is a struct that implements the `Writer` interface for writing documents to the current working directory.
type FileWriter ¶
type FileWriter struct { Writer // contains filtered or unexported fields }
FileWriter is a struct that implements the `Writer` interface for writing documents as files on a local disk.
func (*FileWriter) Close ¶
func (wr *FileWriter) Close(ctx context.Context) error
Close closes the underlying writer mechanism.
func (*FileWriter) Flush ¶
func (wr *FileWriter) Flush(ctx context.Context) error
Flush is a no-op and returns nil.
func (*FileWriter) Write ¶
func (wr *FileWriter) Write(ctx context.Context, path string, fh io.ReadSeeker) (int64, error)
Write copies the content of 'fh' to 'path', where 'path' is assumed to be relative to the root path defined in the constuctor. If the root directory for 'path' does not exist it will be created.
type IOWriter ¶
type IOWriter struct { Writer // contains filtered or unexported fields }
IOWriter is a struct that implements the `Writer` interface for writing documents to an `io.Writer` instance.
func (*IOWriter) Write ¶
Write copies the content of 'fh' to 'path'. It is assumed that either 'io_wr' was created using the NewIOWriterWithWriter method in which there is an explicit `io.Writer` target or that 'ctx' contains a valid `io.Writer` instance that has been assigned by the `SetIOWriterWithContext` method.
type MultiWriter ¶
type MultiWriter struct { Writer // contains filtered or unexported fields }
Type MultiWriter implements the `Writer` interface for writing documents to multiple `Writer` instances.
func (*MultiWriter) Close ¶
func (mw *MultiWriter) Close(ctx context.Context) error
Closes closes each of the underlying `Writer` instances (in the order they were specified to the 'mw' instance) unless 'mw' was created by `NewAsyncMultiWriter`.
func (*MultiWriter) Flush ¶
func (mw *MultiWriter) Flush(ctx context.Context) error
Flushes publishes any outstanding data for each of the underlying `Writer` instances (in the order they were specified to the 'mw' instance) unless 'mw' was created by `NewAsyncMultiWriter`.
func (*MultiWriter) SetLogger ¶
SetLogger assign 'logger' to each of the underlying `Writer` instances (in the order they were specified to the 'mw' instance) unless 'mw' was created by `NewAsyncMultiWriter`.
func (*MultiWriter) Write ¶
func (mw *MultiWriter) Write(ctx context.Context, key string, fh io.ReadSeeker) (int64, error)
Write copies the contents of 'fh' to each of the writers contained by 'mw' in the order they were specified unless 'mw' was created by `NewAsyncMultiWriter`.
func (*MultiWriter) WriterURI ¶
func (mw *MultiWriter) WriterURI(ctx context.Context, key string) string
WriteURI returns an empty string. Because 'mw' has multiple underlying `Writer` instances each of which specifies their own `WriteURI` methods it's either a choice of returning a concatenated string (with all the values) or an empty string. The decision was made to opt for the latter.
type MultiWriterOptions ¶
type NullWriter ¶
type NullWriter struct {
Writer
}
NullWriter is a struct that implements the `Writer` interface for writing documents to nowhere.
func (*NullWriter) Close ¶
func (wr *NullWriter) Close(ctx context.Context) error
Close is a no-op to conform to the `Writer` instance and returns nil.
func (*NullWriter) Flush ¶
func (wr *NullWriter) Flush(ctx context.Context) error
Flush is a no-op to conform to the `Writer` instance and returns nil.
func (*NullWriter) SetLogger ¶
SetLogger is a no-op to conform to the `Writer` instance and returns nil.
func (*NullWriter) Write ¶
func (wr *NullWriter) Write(ctx context.Context, path string, fh io.ReadSeeker) (int64, error)
Write copies the content of 'fh' to 'path' using an `io.Discard` writer.
type StdoutWriter ¶
type StdoutWriter struct {
Writer
}
StdoutWriter is a struct that implements the `Writer` interface for writing documents to STDOUT.
func (*StdoutWriter) Close ¶
func (wr *StdoutWriter) Close(ctx context.Context) error
Close is a no-op to conform to the `Writer` instance and returns nil.
func (*StdoutWriter) Flush ¶
func (wr *StdoutWriter) Flush(ctx context.Context) error
Flush is a no-op to conform to the `Writer` instance and returns nil.
func (*StdoutWriter) Write ¶
func (wr *StdoutWriter) Write(ctx context.Context, path string, fh io.ReadSeeker) (int64, error)
Write copies the content of 'fh' to 'path' using an `os.Stdout` writer.
type Writer ¶
type Writer interface { // Writer copies the contents of an `io.ReadSeeker` instance to a relative path. // The absolute path for the file is determined by the instance implementing the `Writer` interface. Write(context.Context, string, io.ReadSeeker) (int64, error) // WriterURI returns the absolute URI for an instance implementing the `Writer` interface. WriterURI(context.Context, string) string // Flush publishes any outstanding data. The details of if, how or where data is "published" is determined by individual implementations. Flush(context.Context) error // Close closes any underlying writing mechnisms for an instance implementing the `Writer` interface. Close(context.Context) error // SetLogger assigns a custom logger to a `Writer` instance SetLogger(context.Context, *log.Logger) error }
Writer is an interface for writing data to multiple sources or targets.
func NewAsyncMultiWriter ¶
NewMultiWriter returns a Writer instance that will send all writes to each instance in 'writers' asynchronously.
func NewCwdWriter ¶
NewCwdWriter returns a new `CwdWriter` instance for writing documents to the current working directory configured by 'uri' in the form of:
cwd://
Technically 'uri' can also be an empty string.
func NewFileWriter ¶
NewFileWriter returns a new `FileWriter` instance for writing documents as files on a local disk, configured by 'uri' in the form of:
fs://{PATH}
Where {PATH} is an absolute path to an existing directory where files will be written.
func NewIOWriter ¶
NewIOWriter returns a new `IOWriter` instance for writing documents to an `io.Writer` instance configured by 'uri' in the form of:
io://
In order to assign the actual `io.Writer` instance to use you will need to call the `SetIOWriterWithContext` method and pass the resultant `context.Context` instance to the `Write` method.
func NewIOWriterWithWriter ¶ added in v3.1.0
NewIOWriter returns a new `IOWriter` instance for writing documents to 'wr'.
func NewMultiWriter ¶
NewMultiWriter returns a Writer instance that will send all writes to each instance in 'writers'. Writes happen synchronolously in the order in which the underlying Writer instances are specified.
func NewMultiWriterWithOptions ¶
func NewMultiWriterWithOptions(ctx context.Context, opts *MultiWriterOptions) (Writer, error)
NewMultiWriterWithOptions returns a Writer instance derived from 'opts'.
func NewNullWriter ¶
NewNullWriter returns a new `CwdWriter` instance for writing documents to nowhere configured by 'uri' in the form of:
null://
Technically 'uri' can also be an empty string.
func NewRepoWriter ¶
NewRepoWriter is a convenience method to update 'uri' by appending a `data` directory to its path and changing its scheme to `fs://` before invoking NewWriter with the updated URI.
func NewStdoutWriter ¶
NewStdoutWriter returns a new `CwdWriter` instance for writing documents to STDOUT configured by 'uri' in the form of:
stdout://
Technically 'uri' can also be an empty string.
func NewWriter ¶
NewWriter returns a new `Writer` instance configured by 'uri'. The value of 'uri' is parsed as a `url.URL` and its scheme is used as the key for a corresponding `WriterInitializationFunc` function used to instantiate the new `Writer`. It is assumed that the scheme (and initialization function) have been registered by the `RegisterWriter` method.