-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathexample_test.go
39 lines (33 loc) · 1.03 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package styx_test
import (
"io"
"log"
"os"
"time"
"aqwari.net/net/styx"
)
type emptyDir struct{}
func (emptyDir) Readdir(n int) ([]os.FileInfo, error) { return nil, io.EOF }
func (emptyDir) Mode() os.FileMode { return os.ModeDir | 0777 }
func (emptyDir) IsDir() bool { return true }
func (emptyDir) ModTime() time.Time { return time.Now() }
func (emptyDir) Name() string { return "" }
func (emptyDir) Size() int64 { return 0 }
func (emptyDir) Sys() interface{} { return nil }
func Example() {
// Run a file server that creates directories (and only directories)
// on-demand, as a client walks to them.
h := styx.HandlerFunc(func(s *styx.Session) {
for s.Next() {
switch t := s.Request().(type) {
case styx.Tstat:
t.Rstat(emptyDir{}, nil)
case styx.Twalk:
t.Rwalk(emptyDir{}, nil)
case styx.Topen:
t.Ropen(emptyDir{}, nil)
}
}
})
log.Fatal(styx.ListenAndServe(":564", h))
}