filebrowser

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedFile = errors.New("unsupported file type")
	ErrFileTooLarge    = errors.New("file too large")
)

Sentinel errors for file browser operations.

Functions

This section is empty.

Types

type Browser

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

func New

func New(logger *slog.Logger) *Browser

func (*Browser) List

func (b *Browser) List(dir string, hidden bool) (*ListResult, error)

func (*Browser) ServeRaw

func (b *Browser) ServeRaw(w http.ResponseWriter, r *http.Request, path string)

func (*Browser) ValidatePath added in v0.5.0

func (b *Browser) ValidatePath(path string) error

ValidatePath checks that the given path is under an allowed root directory.

func (*Browser) View

func (b *Browser) View(path string) (*FileView, error)

type DirEntry

type DirEntry struct {
	Name    string `json:"name"`
	Type    string `json:"type"` // "dir" or "file"
	Size    int64  `json:"size"` // 0 for directories
	ModTime string `json:"modTime"`
}

type FileView

type FileView struct {
	Path     string `json:"path"`
	Type     string `json:"type"` // "text" or "image"
	Content  string `json:"content,omitempty"`
	Language string `json:"language,omitempty"`
	Mime     string `json:"mime,omitempty"`
	Size     int64  `json:"size"`
	URL      string `json:"url,omitempty"`
}

type ListResult

type ListResult struct {
	Path    string     `json:"path"`
	Entries []DirEntry `json:"entries"`
}

Jump to

Keyboard shortcuts

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