loaders

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")
View Source
var GithubPathRewriter = NewPrefixPathRewriter("github", "github.com/", "github")

Functions

func RewritePath

func RewritePath(pathRewriters []PathRewriterFunc, path *apiprogram.Path) (*apiprogram.Path, error)

Types

type LoaderFunc

type LoaderFunc func(context.Context, *apiprogram.Path) (content []byte, ver string, _ error)

func NewFSLoader

func NewFSLoader(rootFS fs.FS, root string) LoaderFunc

WARNING: does not protect again relative paths. [# path-protect #] should do that.

func NewGithubLoader

func NewGithubLoader(l L.L, getClient func(context.Context, string, string) (*github.Client, error)) LoaderFunc

func NewRootFSLoader added in v0.12.3

func NewRootFSLoader() LoaderFunc

type Loaders

type Loaders struct {

	// Only first that does not return nil is taken into account.
	// These apply only to paths without schemes. Versions are unaffected.
	PathRewriters []PathRewriterFunc

	// scheme -> loader
	CommonLoaders map[string]LoaderFunc

	L L.Nullable
}

func (*Loaders) Fetch

func (p *Loaders) Fetch(
	ctx context.Context,
	pid apiproject.ProjectID,
	path *apiprogram.Path,
) ([]byte, string, error)

func (*Loaders) RewritePath

func (p *Loaders) RewritePath(path *apiprogram.Path) (*apiprogram.Path, error)

func (*Loaders) SetCommonLoader

func (p *Loaders) SetCommonLoader(scheme string, loader LoaderFunc)

type PathRewriterFunc

type PathRewriterFunc func(string) (_ *apiprogram.Path, name string, _ error)

If not rewritten, must return nil.

func NewPrefixPathRewriter

func NewPrefixPathRewriter(name, prefix, newScheme string) PathRewriterFunc

If in has prefix, return new path with newScheme and prefix dropped. Essentially map prefix into a scheme, and drop the prefix from the input path.

Jump to

Keyboard shortcuts

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