httpfs

package
v0.0.0-...-cf82ea8 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package httpfs exposes a directory on the disk via a HTTP inteface with r/w access.

Only the GET/POST verbs are used, GET is used for read-only access to directories and files. POST is used to write files, the path to a file is created. There is no way to create a directory without creating a new file

This package is purely experimental and can change at any time, if you are using it just let me know.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCannotWrite      = errors.New("cannot write")
	ErrCannotRead       = errors.New("cannot read")
	ErrCannotWriteToDir = errors.New("cannot write to directory")
	ErrCannotTruncate   = errors.New("file don't allow truncate")
	ErrCannotCreate     = errors.New("cannot create the file")
	ErrNotFound         = errors.New("file not found")
)

Functions

func DeepReadTo

func DeepReadTo(out io.Writer, in File, depth int) error

func ReadFileTo

func ReadFileTo(out io.Writer, in File) error

func Truncate

func Truncate(in File) error

func WriteToFile

func WriteToFile(out File, in io.Reader) error

Types

type DiskFile

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

Represent a actual disk file

func (*DiskFile) Childs

func (df *DiskFile) Childs() ([]string, error)

func (*DiskFile) Create

func (df *DiskFile) Create(name string, isdir bool) (File, error)

func (*DiskFile) Info

func (df *DiskFile) Info() Info

func (*DiskFile) Open

func (df *DiskFile) Open(name string) (File, error)

func (*DiskFile) Reader

func (df *DiskFile) Reader() (io.ReadCloser, error)

func (*DiskFile) Truncate

func (df *DiskFile) Truncate() error

func (*DiskFile) Writer

func (df *DiskFile) Writer() (io.WriteCloser, error)

type File

type File interface {
	Info() Info
	Open(name string) (File, error)
	Reader() (io.ReadCloser, error)
	Writer() (io.WriteCloser, error)
	Childs() ([]string, error)
	Create(name string, isDir bool) (File, error)
}

func NewDiskFile

func NewDiskFile(filename string) (File, error)

func OpenOrCreate

func OpenOrCreate(root File, createParents bool, path ...string) (File, error)

func Walk

func Walk(root File, path ...string) (File, error)

type Handler

type Handler struct {
	Root File
}

Handler

func (*Handler) Read

func (h *Handler) Read(w http.ResponseWriter, req *http.Request)

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Handler) Write

func (h *Handler) Write(w http.ResponseWriter, req *http.Request)

type Info

type Info struct {
	Name     string
	Dir      bool
	CanRead  bool
	CanWrite bool
}

type ReadArgs

type ReadArgs struct {
	DeepRead bool
	Depth    int
}

type TreeNode

type TreeNode struct {
	Parent *TreeNode
	Childs []*TreeNode
	File   File
}

TreeNode is used to represent the hierarchy between files

func BuildTreeNode

func BuildTreeNode(root File, depth int) (*TreeNode, error)

func (*TreeNode) WriteAbsPath

func (tn *TreeNode) WriteAbsPath(out io.Writer) (n int, err error)

Will write the abs path of this node to the given output

type Truncable

type Truncable interface {
	Truncate() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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