Documentation
¶
Overview ¶
Package source provides the Source interface. All source drivers must implement this interface, register themselves, optionally provide a `WithInstance` function and pass the tests in package source/testing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DirectoryReader ¶
type DirectoryReader struct {
DirectoryPath string
FileReaders []*FileReader
SubDirectories []*DirectoryReader
}
type Driver ¶
type Driver interface {
// Open returns a a new driver instance configured with parameters
// coming from the URL string.
Open(url string) (Driver, error)
// Close closes the underlying source instance managed by the driver.
Close() error
// ReadFiles returns `FileReader` slice for the file at the given relative directory
// that match the given pattern. Returns `nil` if relative path does not exist.
ReadFiles(relativeDir string, fileNamePattern string) (files []*FileReader, err error)
// ReadDirectories returns `DirectoryReader` slice for the directories at the given relative directory
// that match the given pattern. Returns `nil` if relative path does not exist.
ReadDirectories(relativeDir string, dirNamePattern string) (files []*DirectoryReader, err error)
// ReadTree returns a `DirectoryReader` for directory at the given relative path
// with the `SubDirectories` member recursively populated. Returns `nil` if the path
// does not exist.
ReadTree(relativeDir string, fileNamePattern string) (tree *DirectoryReader, err error)
}
Driver is the interface every source driver must implement.
How to implement a source driver?
- Implement this interface.
- Optionally, add a function named `WithInstance`. This function should accept an existing source instance and a Config{} struct and return a driver instance.
- Add a test that calls source/testing.go:Test()
- Add own tests for Open(), WithInstance() (when provided) and Close(). All other functions are tested by tests in source/testing. Saves you some time and makes sure all source drivers behave the same way.
- Call Register in init().
Guidelines:
- All configuration input must come from the URL string in func Open() or the Config{} struct in WithInstance. Don't os.Getenv().
- Drivers are supposed to be read only.
- Ideally don't load any contents (into memory) in Open or WithInstance.
type FileReader ¶
type FileReader struct {
FilePath string
Reader io.ReadCloser
}
Click to show internal directories.
Click to hide internal directories.