fs

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StatikCachingTime = 5 * time.Minute

Functions

This section is empty.

Types

type Statik

type Statik struct {
	StatikDirInfo
	Directories []StatikDirInfo  `json:"directories"`
	Files       []StatikFileInfo `json:"files"`
}

func (Statik) Close

func (s Statik) Close() error

func (Statik) Read

func (s Statik) Read(_ []byte) (_ int, _ error)

func (Statik) Readdir

func (s Statik) Readdir(count int) ([]iofs.FileInfo, error)

func (Statik) Seek

func (s Statik) Seek(_ int64, _ int) (int64, error)

func (Statik) Stat

func (s Statik) Stat() (iofs.FileInfo, error)

func (Statik) Write

func (s Statik) Write(_ []byte) (n int, err error)

type StatikDirInfo

type StatikDirInfo struct {
	Url         string    `json:"url"`
	Time        time.Time `json:"time"`
	GeneratedAt time.Time `json:"generated_at"`
	NameRaw     string    `json:"name"`
	Path        string    `json:"path"`
	SizeRaw     string    `json:"size"`
}

StatikDirInfo represents a directory in Statik

func (StatikDirInfo) IsDir

func (d StatikDirInfo) IsDir() bool

func (StatikDirInfo) ModTime

func (d StatikDirInfo) ModTime() time.Time

func (StatikDirInfo) Mode

func (d StatikDirInfo) Mode() iofs.FileMode

func (StatikDirInfo) Name

func (d StatikDirInfo) Name() string

func (StatikDirInfo) Size

func (d StatikDirInfo) Size() int64

Size implements fs.FileInfo for StatikDirInfo and Statik

func (StatikDirInfo) Sys

func (d StatikDirInfo) Sys() any

type StatikFS

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

StatikFS represents a virtual filesystem that is backed by a statik.json files in a remote server.

cache is a map from path to Statik, where path is the path of the directory containing the statik.json file. cacheLock is a RW mutex that protects cache. It is used by GetStatik and cacheStatik.

func NewStatikFS

func NewStatikFS(base string) *StatikFS

NewStatikFS returns a new StatikFS that is backed by a statik.json file in the remote server at base url.

The returned StatikFS is read-only. The returned StatikFS is goroutine-safe.

func (*StatikFS) GetStatik

func (m *StatikFS) GetStatik(path string) (Statik, error)

GetStatik returns the Statik struct for the statik.json file in the directory specified by path.

If the statik.json file is not cached, it is fetched from the remote server, cached and returned.

The function is safe for concurrent use, as it uses a RW mutex to protect the cache.

func (*StatikFS) Mkdir

func (m *StatikFS) Mkdir(_ context.Context, _ string, _ os.FileMode) error

Mkdir implements webdav.FileSystem for StatikFS.

func (*StatikFS) OpenFile

func (m *StatikFS) OpenFile(
	ctx context.Context,
	name string,
	flag int,
	perm os.FileMode,
) (webdav.File, error)

OpenFile implements webdav.FileSystem for StatikFS.

func (*StatikFS) RemoveAll

func (m *StatikFS) RemoveAll(_ context.Context, _ string) error

RemoveAll implements webdav.FileSystem for StatikFS.

func (*StatikFS) Rename

func (m *StatikFS) Rename(_ context.Context, _, _ string) error

Rename implements webdav.FileSystem for StatikFS.

func (*StatikFS) Stat

func (m *StatikFS) Stat(_ context.Context, name string) (os.FileInfo, error)

Stat implements webdav.FileSystem for StatikFS.

type StatikFileInfo

type StatikFileInfo struct {
	NameRaw string    `json:"name"`
	Path    string    `json:"path"`
	Url     string    `json:"url"`
	Mime    string    `json:"mime"`
	SizeRaw string    `json:"size"`
	Time    time.Time `json:"time"`
}

func (StatikFileInfo) IsDir

func (f StatikFileInfo) IsDir() bool

func (StatikFileInfo) ModTime

func (f StatikFileInfo) ModTime() time.Time

func (StatikFileInfo) Mode

func (f StatikFileInfo) Mode() fs.FileMode

func (StatikFileInfo) Name

func (f StatikFileInfo) Name() string

func (StatikFileInfo) Size

func (f StatikFileInfo) Size() int64

Size implements fs.FileInfo for StatikFileInfo

func (StatikFileInfo) Sys

func (f StatikFileInfo) Sys() any

Jump to

Keyboard shortcuts

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