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 ¶
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")
Click to show internal directories.
Click to hide internal directories.