httpfs

package
v0.0.0-...-4cb4b50 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Patch

func Patch(ctx context.Context, fsys fs.FS, name string, tarBuf bytes.Buffer) error

Types

type Cacher

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

Cacher wraps an FS and adds caching functionality

func NewCacher

func NewCacher(fs *FS) *Cacher

NewCacher creates a new caching wrapper around an FS

func (*Cacher) CacheNode

func (fsys *Cacher) CacheNode(node *Node)

CacheNode stores node result in cache with appropriate TTL

func (*Cacher) CacheNodeError

func (fsys *Cacher) CacheNodeError(path string, err error)

CacheNodeError stores node request error in cache

func (*Cacher) CachedNode

func (fsys *Cacher) CachedNode(path string) (*Node, error, bool)

CachedNode retrieves cached node result if valid

func (*Cacher) Chmod

func (fsys *Cacher) Chmod(name string, mode fs.FileMode) error

Chmod changes the mode of the named file

func (*Cacher) ChmodContext

func (fsys *Cacher) ChmodContext(ctx context.Context, name string, mode fs.FileMode) error

ChmodContext changes file mode with context

func (*Cacher) Chown

func (fsys *Cacher) Chown(name string, uid, gid int) error

Chown changes the numeric uid and gid of the named file

func (*Cacher) ChownContect

func (fsys *Cacher) ChownContect(ctx context.Context, name string, uid, gid int) error

ChownContect changes ownership with context

func (*Cacher) Chtimes

func (fsys *Cacher) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes changes the access and modification times of the named file

func (*Cacher) ChtimesContext

func (fsys *Cacher) ChtimesContext(ctx context.Context, name string, atime time.Time, mtime time.Time) error

ChtimesContext changes times with context

func (*Cacher) Create

func (fsys *Cacher) Create(name string) (fs.File, error)

Create creates or truncates the named file

func (*Cacher) CreateContext

func (fsys *Cacher) CreateContext(ctx context.Context, name string, content []byte, mode fs.FileMode) (fs.File, error)

CreateContext is a helper for creating files with content and mode

func (*Cacher) GetTTL

func (fsys *Cacher) GetTTL() time.Duration

GetTTL returns the current directory cache TTL

func (*Cacher) InvalidateAll

func (fsys *Cacher) InvalidateAll(name string)

InvalidateAll clears all cached node results

func (*Cacher) InvalidateNode

func (fsys *Cacher) InvalidateNode(path string, resync, recursive bool) error

InvalidateNode invalidates a node in the cache

func (*Cacher) Mkdir

func (fsys *Cacher) Mkdir(name string, perm fs.FileMode) error

Mkdir creates a directory

func (*Cacher) MkdirContext

func (fsys *Cacher) MkdirContext(ctx context.Context, name string, perm fs.FileMode) error

MkdirContext creates a directory with context

func (*Cacher) Open

func (fsys *Cacher) Open(name string) (fs.File, error)

Open opens the named file for reading

func (*Cacher) OpenContext

func (fsys *Cacher) OpenContext(ctx context.Context, name string) (fs.File, error)

OpenContext opens the named file for reading with context

func (*Cacher) Patch

func (fsys *Cacher) Patch(ctx context.Context, name string, tarBuf bytes.Buffer) error

Patch applies a tar patch to the filesystem

func (*Cacher) PullDir

func (fsys *Cacher) PullDir(ctx context.Context, name string) (*Node, error)

PullDir gets metadata for a directory and its entries using multipart response. Called async on cache lookup w/ renewal, called sync on cache invalidate w/ resync. Called sync on StatContext w/ cache miss.

func (*Cacher) PullMeta

func (fsys *Cacher) PullMeta(ctx context.Context, path string) (*Node, error)

PullMeta performs a HEAD request to get metadata. Called async on cache lookup w/ renewal, called sync on StatContext w/ cache miss.

func (*Cacher) PullNode

func (fsys *Cacher) PullNode(ctx context.Context, name string, recursivePrefetch bool) (*Node, []byte, error)

PullNode fetches and caches a node with optional subtree prefetching Called by Open and ReadDir on cache miss.

func (*Cacher) ReadDir

func (fsys *Cacher) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads the named directory and returns a list of directory entries

func (*Cacher) ReadDirContext

func (fsys *Cacher) ReadDirContext(ctx context.Context, name string) ([]fs.DirEntry, error)

ReadDirContext reads the named directory with context

func (fsys *Cacher) Readlink(name string) (string, error)

Readlink reads the value of a symbolic link

func (*Cacher) ReadlinkContext

func (fsys *Cacher) ReadlinkContext(ctx context.Context, name string) (string, error)

ReadlinkContext reads the value of a symbolic link with context

func (*Cacher) Remove

func (fsys *Cacher) Remove(name string) error

Remove removes a file or empty directory

func (*Cacher) RemoveContext

func (fsys *Cacher) RemoveContext(ctx context.Context, name string) error

RemoveContext removes a file or directory with context

func (*Cacher) Rename

func (fsys *Cacher) Rename(oldname, newname string) error

Rename renames a file or directory

func (*Cacher) RenameContext

func (fsys *Cacher) RenameContext(ctx context.Context, oldname, newname string) error

RenameContext renames a file or directory with context

func (*Cacher) SetTTL

func (fsys *Cacher) SetTTL(ttl time.Duration)

SetTTL sets the cache TTL for directory nodes

func (*Cacher) Stat

func (fsys *Cacher) Stat(name string) (fs.FileInfo, error)

Stat returns file information

func (*Cacher) StatContext

func (fsys *Cacher) StatContext(ctx context.Context, name string) (fs.FileInfo, error)

StatContext performs a HEAD request to get file metadata if not cached

func (fsys *Cacher) Symlink(oldname, newname string) error

Symlink creates a symbolic link

func (*Cacher) SymlinkContext

func (fsys *Cacher) SymlinkContext(ctx context.Context, oldname, newname string) error

SymlinkContext creates a symbolic link with context

func (*Cacher) WriteFile

func (fsys *Cacher) WriteFile(name string, data []byte, perm fs.FileMode) error

WriteFile writes data to the named file, creating it if necessary

func (*Cacher) WriteFileContext

func (fsys *Cacher) WriteFileContext(ctx context.Context, name string, data []byte, perm fs.FileMode, modTime time.Time) error

WriteFileContext writes data to the named file with context

type FS

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

FS implements an HTTP-backed filesystem following the design specification

func New

func New(baseURL string, client *http.Client) *FS

New creates a new HTTP filesystem with the given base URL

func (*FS) Chmod

func (fsys *FS) Chmod(name string, mode fs.FileMode) error

Chmod changes the mode of the named file

func (*FS) ChmodContext

func (fsys *FS) ChmodContext(ctx context.Context, name string, mode fs.FileMode) error

ChmodContext changes file mode with context

func (*FS) Chown

func (fsys *FS) Chown(name string, uid, gid int) error

Chown changes the numeric uid and gid of the named file

func (*FS) ChownContect

func (fsys *FS) ChownContect(ctx context.Context, name string, uid, gid int) error

ChownContect changes ownership with context

func (*FS) Chtimes

func (fsys *FS) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes changes the access and modification times of the named file

func (*FS) ChtimesContext

func (fsys *FS) ChtimesContext(ctx context.Context, name string, atime time.Time, mtime time.Time) error

ChtimesContext changes times with context

func (*FS) Create

func (fsys *FS) Create(name string) (fs.File, error)

Create creates or truncates the named file

func (*FS) CreateContext

func (fsys *FS) CreateContext(ctx context.Context, name string, content []byte, mode fs.FileMode) (fs.File, error)

CreateContext is a helper for creating files with content and mode

func (*FS) Ignore

func (fsys *FS) Ignore(names ...string)

func (*FS) Index

func (fsys *FS) Index(ctx context.Context, name string) (fs.FS, error)

func (*FS) Mkdir

func (fsys *FS) Mkdir(name string, perm fs.FileMode) error

Mkdir creates a directory

func (*FS) MkdirContext

func (fsys *FS) MkdirContext(ctx context.Context, name string, perm fs.FileMode) error

MkdirContext creates a directory with context

func (*FS) Open

func (fsys *FS) Open(name string) (fs.File, error)

Open opens the named file for reading

func (*FS) OpenContext

func (fsys *FS) OpenContext(ctx context.Context, name string) (fs.File, error)

OpenContext opens the named file for reading with context

func (*FS) Patch

func (fsys *FS) Patch(ctx context.Context, name string, tarBuf bytes.Buffer) error

func (*FS) ReadDir

func (fsys *FS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads the named directory and returns a list of directory entries

func (*FS) ReadDirContext

func (fsys *FS) ReadDirContext(ctx context.Context, name string) ([]fs.DirEntry, error)

ReadDirContext reads the named directory with context

func (*FS) ReadFile

func (fsys *FS) ReadFile(name string) ([]byte, error)

func (*FS) ReadFileContext

func (fsys *FS) ReadFileContext(ctx context.Context, name string) ([]byte, error)
func (fsys *FS) Readlink(name string) (string, error)

func (*FS) ReadlinkContext

func (fsys *FS) ReadlinkContext(ctx context.Context, name string) (string, error)

func (*FS) Remove

func (fsys *FS) Remove(name string) error

Remove removes a file or empty directory

func (*FS) RemoveContext

func (fsys *FS) RemoveContext(ctx context.Context, name string) error

RemoveContext removes a file or directory with context

func (*FS) Rename

func (fsys *FS) Rename(oldname, newname string) error

func (*FS) RenameContext

func (fsys *FS) RenameContext(ctx context.Context, oldname, newname string) error

func (*FS) SetLogger

func (fsys *FS) SetLogger(logger *slog.Logger)

SetLogger sets the logger for the filesystem

func (*FS) Stat

func (fsys *FS) Stat(name string) (fs.FileInfo, error)

Stat returns file information

func (*FS) StatContext

func (fsys *FS) StatContext(ctx context.Context, name string) (fs.FileInfo, error)

StatContext performs a HEAD request to get file metadata

func (fsys *FS) Symlink(oldname, newname string) error

func (*FS) SymlinkContext

func (fsys *FS) SymlinkContext(ctx context.Context, oldname, newname string) error

func (*FS) WriteFile

func (fsys *FS) WriteFile(name string, data []byte, perm fs.FileMode) error

WriteFile writes data to the named file, creating it if necessary

func (*FS) WriteFileContext

func (fsys *FS) WriteFileContext(ctx context.Context, name string, data []byte, perm fs.FileMode, modTime time.Time) error

WriteFileContext writes data to the named file with context

type Node

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

Node represents a file or directory node

func ParseNode

func ParseNode(fsys wrappedFS, path string, headers http.Header, content []byte) (*Node, error)

ParseNode extracts file information from HTTP headers and creates a fileNode

func (*Node) Close

func (n *Node) Close() error

func (*Node) Entries

func (n *Node) Entries() []fs.DirEntry

Entries returns the directory entries (for directories)

func (*Node) Info

func (n *Node) Info() (fs.FileInfo, error)

func (*Node) IsDir

func (n *Node) IsDir() bool

func (*Node) ModTime

func (n *Node) ModTime() time.Time

func (*Node) Mode

func (n *Node) Mode() fs.FileMode

func (*Node) Name

func (n *Node) Name() string

fs.FileInfo interface implementation

func (*Node) Path

func (n *Node) Path() string

Path returns the full path of this node

func (*Node) Read

func (n *Node) Read(p []byte) (int, error)

func (*Node) ReadDir

func (n *Node) ReadDir(count int) ([]fs.DirEntry, error)

fs.ReadDirFile interface implementation

func (*Node) Seek

func (n *Node) Seek(offset int64, whence int) (int64, error)

func (*Node) Size

func (n *Node) Size() int64

func (*Node) Stat

func (n *Node) Stat() (fs.FileInfo, error)

fs.File interface implementation (minimal)

func (*Node) Sys

func (n *Node) Sys() interface{}

func (*Node) ToNode

func (n *Node) ToNode() *fskit.Node

func (*Node) Type

func (n *Node) Type() fs.FileMode

fs.DirEntry interface implementation

func (*Node) Write

func (f *Node) Write(p []byte) (int, error)

type PatchFS

type PatchFS interface {
	fs.FS
	Patch(ctx context.Context, name string, tarBuf bytes.Buffer) error
}

type Server

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

Server implements an HTTP server that serves an fs.FS using the httpfs protocol

func NewServer

func NewServer(fsys fs.FS) *Server

NewServer creates a new HTTP server for the given filesystem

func NewServerWithPrefix

func NewServerWithPrefix(fsys fs.FS, prefix string) *Server

NewServerWithPrefix creates a new HTTP server with a URL prefix

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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