Documentation
¶
Overview ¶
Example:
package main
import (
"context"
"github.com/whosonfirst/go-reader"
"io"
"os"
)
func main() {
ctx := context.Background()
r, _ := reader.NewReader(ctx, "fs:///usr/local/data")
fh, _ := r.Read(ctx, "example.txt")
defer fh.Close()
io.Copy(os.Stdout, fh)
}
Package reader provides a common interface for reading from a variety of sources. It has the following interface:
type Reader interface {
Read(context.Context, string) (io.ReadSeekCloser, error)
ReaderURI(string) string
}
Reader intstances are created either by calling a package-specific New{SOME_READER}Reader method or by invoking the reader.NewReader method passing in a context.Context instance and a URI specific to the reader class. For example:
r, _ := reader.NewReader(ctx, "fs:///usr/local/data")
Custom reader packages implement the reader.Reader interface and register their availability by calling the reader.RegisterRegister method on initialization. For example:
func init() {
ctx := context.Background()
err = RegisterReader(ctx, "file", NewFileReader)
if err != nil {
panic(err)
}
}
Index ¶
- func Readers() []string
- func RegisterReader(ctx context.Context, scheme string, init_func ReaderInitializationFunc) error
- func Schemes() []string
- type FileReader
- type MultiReader
- type NullReader
- type Reader
- func NewFileReader(ctx context.Context, uri string) (Reader, error)
- func NewMultiReader(ctx context.Context, readers ...Reader) (Reader, error)
- func NewMultiReaderFromURIs(ctx context.Context, uris ...string) (Reader, error)
- func NewNullReader(ctx context.Context, uri string) (Reader, error)
- func NewReader(ctx context.Context, uri string) (Reader, error)
- func NewStdinReader(ctx context.Context, uri string) (Reader, error)
- type ReaderInitializationFunc
- type StdinReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterReader ¶ added in v0.1.1
func RegisterReader(ctx context.Context, scheme string, init_func ReaderInitializationFunc) error
Types ¶
type FileReader ¶
type FileReader struct {
Reader
// contains filtered or unexported fields
}
func (*FileReader) Read ¶
func (r *FileReader) Read(ctx context.Context, path string) (io.ReadSeekCloser, error)
type MultiReader ¶ added in v0.2.1
type MultiReader struct {
Reader
// contains filtered or unexported fields
}
func (*MultiReader) Read ¶ added in v0.2.1
func (mr *MultiReader) Read(ctx context.Context, uri string) (io.ReadSeekCloser, error)
type NullReader ¶
type NullReader struct {
Reader
}
func (*NullReader) Read ¶
func (r *NullReader) Read(ctx context.Context, uri string) (io.ReadSeekCloser, error)
type Reader ¶
type Reader interface {
Read(context.Context, string) (io.ReadSeekCloser, error)
ReaderURI(context.Context, string) string
}
func NewMultiReader ¶ added in v0.2.1
func NewMultiReaderFromURIs ¶ added in v0.2.1
type ReaderInitializationFunc ¶ added in v0.1.1
type StdinReader ¶ added in v0.8.0
type StdinReader struct {
Reader
}
func (*StdinReader) Read ¶ added in v0.8.0
func (r *StdinReader) Read(ctx context.Context, uri string) (io.ReadSeekCloser, error)
Click to show internal directories.
Click to hide internal directories.