Documentation ¶
Overview ¶
Package writer provides a common interface for writing data to one or more sources.
Index ¶
- Constants
- 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
- type FileWriter
- type IOWriter
- type MultiWriter
- type NullWriter
- type StdoutWriter
- type Writer
- 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 NewMultiWriter(writers ...Writer) Writer
- 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 GetIOWriterFromContext ¶ added in v0.2.0
GetIOWriterFromContext returns the `io.Writer` instance associated with the `IOWRITER_TARGET_KEY` value in 'ctx'.
func RegisterWriter ¶ added in v0.1.0
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 ¶ added in v0.7.0
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 ¶ added in v0.3.0
func (wr *FileWriter) Close(ctx context.Context) error
Close closes the underlying writer mechanism.
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 ¶ added in v0.2.0
type IOWriter struct {
Writer
}
IOWriter is a struct that implements the `Writer` interface for writing documents to an `io.Writer` instance.
type MultiWriter ¶ added in v0.5.0
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 ¶ added in v0.5.0
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).
func (*MultiWriter) Write ¶ added in v0.5.0
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.
func (*MultiWriter) WriterURI ¶ added in v0.5.0
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 NullWriter ¶
type NullWriter struct {
Writer
}
NullWriter is a struct that implements the `Writer` interface for writing documents to nowhere.
func (*NullWriter) Close ¶ added in v0.3.0
func (wr *NullWriter) Close(ctx context.Context) error
Close 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 ¶ added in v0.3.0
func (wr *StdoutWriter) Close(ctx context.Context) error
Close 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 // Close closes any underlying writing mechnisms for an instance implementing the `Writer` interface. Close(context.Context) error }
Writer is an interface for writing data to multiple sources or targets.
func NewCwdWriter ¶ added in v0.7.0
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 ¶ added in v0.2.0
NewIOWriter returns a new `IOWriter` instance for writing documents to the current working directory 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 NewMultiWriter ¶ added in v0.5.0
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 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 ¶ added in v0.8.0
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.