files

package
v0.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package files is a layer over a normal directory to synthesize Stat responses, and allow special semantics for Read/Write requests to opened files

Adding

import (
	"os"
	"path"

	"github.com/altid/server/files"
)

type NormalHandler struct{}

func NewNormal() *NormalHandler { return &NormalHandler{} }

func (*NormalHandler) Normal(msg *files.Message) (interface{}, error) {
	fp := path.Join(msg.Service, msg.Buffer, msg.Target)
	return os.Open(fp)
}

func (*NormalHandler) Stat(msg *files.Message) (os.FileInfo, error) {
	fp := path.Join(msg.Service, msg.Buffer, msg.Target)
	return os.Lstat(fp)
}

func main() {
	fh := files.Handle("/path/to/dir")
	fh.Add("/myfile", NewNormal())

	// [...]
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Files

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

Files facilitates access to the functions of the sythetic files

func Handle

func Handle(dir string) *Files

Handle listens for calls to its Stat and Normal functions, and returns a stat or os.File Writes and Reads to real files will be rooted at `dir` Many resulting files are synthesized on demand, others map to a real file that may or may not be rooted at the given directory For example, to send a command to open a buffer

h := Handle("/path/to/my/server")

fp, err := h.Normal("mybuffer", "ctl")
if err != nil {
	log.Fatal(err)
}

defer fp.Close()
fp.WriteString("open foo")

func (*Files) Add

func (f *Files) Add(path string, h Handler)

Add a Handler to the stack

func (*Files) Normal

func (f *Files) Normal(buffer, req string, uuid uint32) (interface{}, error)

Normal will return an interface satisfying io.ReaderAt, io.WriterAt, and io.Closer if the file requested is a regular file If the file requested is a directory, it will synthesize an *os.FileInfo with the correct semantics

func (*Files) Stat

func (f *Files) Stat(buffer, req string, uuid uint32) (os.FileInfo, error)

Stat will synthesize an os.FileInfo (stat) for the named file, if available

type Handler

type Handler interface {
	Stat(msg *Message) (os.FileInfo, error)
	Normal(msg *Message) (interface{}, error)
}

Handler represents calls to a synthetic file

type Message

type Message struct {
	Service string
	Buffer  string
	Target  string
	UUID    uint32
}

Message contains information about which file is being requested The UUID should be set to the client which is requesting the file

Jump to

Keyboard shortcuts

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