source

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Root represents the root of a source filesystem.
	Root = "."

	// ErrSourceNotFound is returned by New() when the source was not found by the scheme.
	ErrSourceNotFound = errors.New("source not found")
)

Functions

func Available

func Available() []string

Available returns a slice of all registered source schemes.

func IsMarkdownFile

func IsMarkdownFile(path string) bool

IsMarkdownFile checks if the file path has a Markdown extension.

func Register

func Register(scheme string, fn SourceFunc)

Register adds the source function by a scheme. If the scheme is already registered, this is a no-op.

Types

type Directory

type Directory struct {
	// contains filtered or unexported fields
}

Directory is a source that reads from a directory on the filesystem.

func (*Directory) Close

func (d *Directory) Close() error

func (*Directory) Open

func (d *Directory) Open(path string) (fs.File, error)

func (*Directory) Watch

func (d *Directory) Watch(files chan<- string, errors chan<- error)

type File

type File struct {
	// contains filtered or unexported fields
}

File is a source that reads from a single file.

func (*File) Close

func (f *File) Close() error

func (*File) Open

func (f *File) Open(path string) (fs.File, error)

func (*File) Watch

func (f *File) Watch(files chan<- string, errors chan<- error)

type Source

type Source interface {
	fs.FS

	// Watch watches the filesystem for changes to Markdown files, sending their paths over the channel files.
	// Errors should be sent over the channel errors.
	Watch(files chan<- string, errors chan<- error)

	// Close closes the source.
	Close() error
}

Source represents a filesystem with Markdown files.

func New

func New(uri string) (Source, error)

New creates a new source given a URI in the format '{scheme}://{path}', i.e. 'file://path/to/markdown/file.md'. If the scheme is not found, ErrSourceNotFound is returned.

func NewDirectory

func NewDirectory(path string) (Source, error)

NewDirectory creates a new directory source.

func NewFile

func NewFile(path string) (Source, error)

NewFile creates a new file source.

func NewStdin

func NewStdin(_ string) (Source, error)

NewStdin creates a new standard input source.

type SourceFunc

type SourceFunc func(path string) (Source, error)

SourceFunc represents a function that creates a source from the given path.

type Stdin

type Stdin struct {
	// contains filtered or unexported fields
}

Stdin is a source that reads from standard input.

func (*Stdin) Close

func (s *Stdin) Close() error

func (*Stdin) Open

func (s *Stdin) Open(name string) (fs.File, error)

func (*Stdin) Watch

func (s *Stdin) Watch(files chan<- string, errors chan<- error)

type VirtualFile

type VirtualFile struct {
	bytes.Buffer
	// contains filtered or unexported fields
}

VirtualFile is a fs.File implementation that wraps a buffer.

func NewVirtualFile

func NewVirtualFile(name string) *VirtualFile

NewVirtualFile creates a new virtual file with the given name.

func (*VirtualFile) Close

func (f *VirtualFile) Close() error

func (*VirtualFile) IsDir

func (f *VirtualFile) IsDir() bool

func (*VirtualFile) ModTime

func (f *VirtualFile) ModTime() time.Time

func (*VirtualFile) Mode

func (f *VirtualFile) Mode() fs.FileMode

func (*VirtualFile) Name

func (f *VirtualFile) Name() string

func (*VirtualFile) Size

func (f *VirtualFile) Size() int64

func (*VirtualFile) Stat

func (f *VirtualFile) Stat() (fs.FileInfo, error)

func (*VirtualFile) Sys

func (f *VirtualFile) Sys() any

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL