-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgopher.go
39 lines (32 loc) · 822 Bytes
/
gopher.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 main
import (
"fmt"
"path"
"github.com/prologic/go-gopher"
)
type GopherConfig struct {
Hostname string
Port string
RootDir string
}
func (c *GopherConfig) String() string {
return fmt.Sprintf("Gopher Config: %v:%v Files:%v", c.Hostname, c.Port, c.RootDir)
}
type indexHandler struct {
rootPath string
rootHandler gopher.Handler
}
func (f *indexHandler) ServeGopher(w gopher.ResponseWriter, r *gopher.Request) {
upath := r.Selector
if gopher.GetItemType(f.rootPath+upath) == gopher.DIRECTORY && upath != "/" {
w.WriteItem(&gopher.Item{
Type: gopher.DIRECTORY,
Selector: path.Dir(upath),
Description: "Go Back",
})
}
f.rootHandler.ServeGopher(w, r)
}
func index(root gopher.FileSystem) *indexHandler {
return &indexHandler{root.Name(), gopher.FileServer(root)}
}