Documentation ¶
Overview ¶
Package resource provides abstractions for accessing resources.
Index ¶
Constants ¶
const Extension = ".corgi"
Extension is the file extension for corgi files.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FSSource ¶
type FSSource struct {
// contains filtered or unexported fields
}
FSSource is a Source that reads files from a fs.FS.
type File ¶
type File struct { // Name is the path to the file, relative to the resource directory it // is located in. // // It includes the file's file extension. Name string // Source is the file's source. Source Source // Contents are the contents of the file. Contents string }
File represents a read resource file.
func ReadCorgiFile ¶
ReadCorgiFile attempts to read the corgi file with the given name, as described in Source.ReadCorgiFile.
If none of the sources return a file, ReadCorgiFile returns a *NotFoundError.
func ReadCorgiLib ¶
ReadCorgiLib attempts to read the corgi library with the given name, as described in Source.ReadCorgiLib.
It returns the first non-nil list of Files. It does not combine files from different sources.
If none of the sources return any files, ReadCorgiLib returns a *NotFoundError.
type NotFoundError ¶
type NotFoundError struct {
Name string
}
NotFoundError is returned when a resource file could not be found.
It is never returned by the Source directly.
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
type Source ¶
type Source interface { // ReadCorgiFile returns the requested Corgi file. // // Name's file extension is optional and might not be present. // // If no file is found, ReadCorgiFile should return nil, nil. ReadCorgiFile(name string) (*File, error) // ReadCorgiLib returns the library files that are available under the // given name. // That name might either point to a directory of corgi files, or to a // single file. // // When accessing a file, the file extension is optional and might not // be present. // // If both a file and a directory with the same name exists, // directories should take precedence, e.g. if name is foo and a // directory foo and a file foo.corgi exists, the dir should be chosen. // // If no file is found, ReadCorgiLib should return nil, nil. ReadCorgiLib(name string) ([]File, error) // ReadFile reads the given file from the resource source. // // The file extension is optional and might not be present. // If name has no extension and a file with the given name and a corgi // file with the name + extension exists, then the file without // extension should be read. // // If no file is found, ReadFile should return nil, nil. ReadFile(name string) (*File, error) // Name returns the name of the source. // It should be unique to the source. // Ideally, it should be the path to the source root, without a // trailing slash. // // It must be the same for all files returned by the source. Name() string }
Source is an interface that allows access to resources providing extended, included, and used files.