source

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package source contains various file sources for Markdown documents.

Index

Constants

View Source
const (
	// Root represents the root document path in a source.
	// Certain sources only serve a single Markdown file and may check for this value to serve that file.
	Root = "."
)

Variables

View Source
var (
	// ErrSourceNotFound means that a source for the URL scheme was not found.
	ErrSourceNotFound = errors.New("source schema not found")
)

Functions

func Must added in v0.4.0

func Must[T any](t T, err error) T

Must unwraps a (value, error) return to just the value. If err is not nil, this panics.

func Parse added in v0.4.0

func Parse(path string) (*url.URL, error)

Parse parses the path into a source.

The path is parsed in order as follows:

* If the path is already a URI, it is passed verbatim to New().

* If the path is a dash ('-'), standard input is used.

* Otherwise, stat the path to check if the path is a file or directory.

func Register

func Register(scheme string, handler Handler)

Register adds a handler for a URL scheme.

Types

type Directory

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

Directory is a source that serves 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() (<-chan string, <-chan error)

type File

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

File is a source that serves a single file on the filesystem.

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() (<-chan string, <-chan error)

type HTTP added in v0.4.0

type HTTP struct {
	fstest.MapFS
}

HTTP is a source that serves a URL.

type Handler added in v0.4.0

type Handler func(*url.URL) (Source, error)

Handler is a function that creates a source from a URL.

func Get added in v0.4.0

func Get(scheme string) Handler

Get returns a handler for the URL scheme.

type Source

type Source interface {
	fs.FS
}

Source is a filesystem serving Markdown files.

func New

func New(u *url.URL) (Source, error)

New creates a source from the URL. If the source for the URL scheme does not exist, ErrSourceNotFound is returned.

func NewDirectory

func NewDirectory(u *url.URL) (Source, error)

NewDirectory creates a new directory source.

func NewFile

func NewFile(u *url.URL) (Source, error)

NewFile creates a new file source.

func NewHTTP added in v0.4.0

func NewHTTP(u *url.URL) (Source, error)

NewHTTP creates a new source, downloading over HTTP(s) from the given URL.

func NewStdin

func NewStdin(_ *url.URL) (Source, error)

NewStdin creates a new standard input source. The URL is ignored.

type Stdin

type Stdin struct {
	fstest.MapFS
}

Stdin is a source that serves standard input.

type Watcher added in v0.4.0

type Watcher interface {
	Source

	// Watch starts watching the source for Markdown file changes,
	// sending them over the files channel.
	// Any error encountered should be sent over the errors channel.
	//
	// When the watcher is closed, both returned channels should be closed.
	Watch() (files <-chan string, errors <-chan error)

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

Watcher is a source that supports file watching.

Jump to

Keyboard shortcuts

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