writefs

package
v0.0.0-...-0d1d0b3 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2025 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

FS interface to read and write.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadAll

func ReadAll(o Opener, path string) ([]byte, error)

func WriteFile

func WriteFile(c Creator, path string, data []byte) error

Types

type CompleteFS

type CompleteFS interface {
	CreateOpener
	// Read files tree and return the index of all regular file.
	FileIndex() ([]string, error)
	// Remove path of a file.
	Remove(path string) error
}

A full feature FS.

func Memory

func Memory() CompleteFS

func Os

func Os(dir string) CompleteFS

type CreateOpener

type CreateOpener interface {
	Creator
	Opener
}

type Creator

type Creator interface {
	Create(path string) (io.WriteCloser, error)
}

A FS to create and write file content.

type Opener

type Opener interface {
	Open(path string) (io.ReadCloser, error)
}

A FS to open file and read the content.

func FS

func FS(fs fs.FS) Opener

Transform a fs.FS from std lib to a Opener for this package.

type SitemapWatcher

type SitemapWatcher struct {
	Creator Creator

	// Add is called on each .WriteFile, return true to keep the path.
	Add func(path string, data []byte) (keep bool)
	// contains filtered or unexported fields
}

SitemapWatcher collect all HTML path to create a sitemap.

func Sitemap

func Sitemap(sub *Creator) *SitemapWatcher

Sitemap replaces sub with a new SitemapWatcher and return it.

func (*SitemapWatcher) Create

func (watcher *SitemapWatcher) Create(path string) (io.WriteCloser, error)

func (*SitemapWatcher) Sitemap

func (watcher *SitemapWatcher) Sitemap(host string) []byte

Sitemap generates a simple sitemap file (one url by line).

The host prefix all line. Host must not end by a '/'. Valid example: `sitemap.Sitemap("https://example.com")`

func (*SitemapWatcher) WriteFile

func (watcher *SitemapWatcher) WriteFile(path string, data []byte) error

type T

type T map[string]int

A test Creator file system to check which file are created.

func (T) Create

func (t T) Create(path string) (io.WriteCloser, error)

type WriteFileFS

type WriteFileFS interface {
	WriteFile(path string, data []byte) error
}

A sub type of Creator with one write.

Jump to

Keyboard shortcuts

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